| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 665 人关注过本帖
标题:[求助]怎么运行不出来啊,谁可以帮忙看看啊,小女子万分感谢
只看楼主 加入收藏
peachzi
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-12-15
收藏
 问题点数:0 回复次数:0 
[求助]怎么运行不出来啊,谁可以帮忙看看啊,小女子万分感谢

好象是路径的那个INIT函数错了,可不知道具体怎么回事
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<dos.h>
#include<time.h>
typedef struct TREE
{
char data;
struct TREE *ichild;
struct TREE *rchild;
int x;
int y;
}Tree;
struct OUTPUT
{
int x;
int y;
int num;
}s;
int nodeNUM=0;
char way;
char str[3];
void Init();
void Close();
Tree *CreatTree();
Tree *InitTree(int h,int t,int w);
void DrawTree(Tree *t);
void preorder(Tree *t);
void posorder(Tree *t);
void inorder(Tree *t);
void DrawNode(Tree *t,int color);
void clrscr();
void main()
{
Tree *root;
randomize();
root=CreatTree();
Init();
DrawTree(root);
sleep(1);
s.x=100;s.y=300;s.num=1;
preorder(root);
getch();
clrscr();
DrawTree(root);
sleep(1);
s.x=100;s.y=350;s.num=1;
inorder(root);
getch();
clrscr();
DrawTree(root);
sleep(1);
s.x=100;s.y=400;s.num=1;
posorder(root);
close();
}
void clrscr()
{
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
bar(0,20,640,280);
}

Tree *CreatTree()
{
Tree *root;
clrscr();
printf("please input n\n");
printf("1.computer creat\n");
printf("2.people creat\n");
way=getch();
if(way!='2')
way='1';
if(way=='2')

printf("please creat the treen\n");
root=InitTree(1,320,150);
system("pause");
return root;
}
Tree *InitTree(int h,int t,int w)
{
char ch;
int n;
Tree *node;
if(way=='2')
scanf("%c",&ch);
else
{
n=random(5);
if(n==0&&nodeNUM>=3)
ch='.';
else
ch=65+random(25);
}
if(ch=='.')
return NULL;
else

{
if(h==6||nodeNUM==26)
return NULL;
node=(Tree*)malloc(sizeof(Tree));
node->data=ch;
node->x=t;
node->y=h*50;
nodeNUM++;
node->ichild=InitTree(h+1,t-w,w/2);
node->rchild=InitTree(h+1,t+w,w/2);
}return node;
}
void DrawTree(Tree *t)
{
if(t!=NULL)
{
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillellipse(t->x,t->y,9,9);

setcolor(WHITE);
circle(t->x,t->y,10);
sprintf(str,"%c",t->data);
outtextxy(t->x-3,t->y-2,str);
if(t->ichild!=NULL)
{
line(t->x-5,t->y+12,t->ichild->x+5,t->ichild->y-12);
DrawTree(t->ichild);
}
if(t->rchild!=NULL)
{ line(t->x+5,t->y+12,t->ichild->x-5,t->ichild->y-12);
DrawTree(t->rchild);
}
}
}

void DrawNode(Tree *t,int color)
{
setcolor(YELLOW);
setfillstyle(SOLID_FILL,YELLOW);
fillellipse(t->x,t->y,10,10);
setcolor(RED);
sprintf(str,"%c",t->data);
outtextxy(t->x-3,t->y-2,str);
setcolor(color);
outtextxy(s.x,s.y,str);
setcolor(RED);
sprintf(str,"%d",s.num);
outtextxy(t->x-3,t->y-20,str);
s.num++;
sleep(1);
}

void preorder(Tree *t)
{
if(t!=NULL)
{
s.x+=15;
DrawNode(t,GREEN);
preorder(t->ichild);
preorder(t->rchild);
}
}
void inorder(Tree *t)
{if(t!=NULL)
{

inorder(t->ichild);
s.x+=15;
DrawNode(t,YELLOW);
inorder(t->rchild);
}
}
void posorder(Tree *t)
{
if(t!=NULL)
{

posorder(t->ichild);
posorder(t->rchild);
s.x+=15;
DrawNode(t,BLUE);

}
}
void Init()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
cleardevice();
setcolor(YELLOW);
outtextxy(250,10,"anykey to continue");
setcolor(RED);
outtextxy(20,300,"preorder");
outtextxy(20,350,"inorder");
outtextxy(20,400,"posorder");
}
void Close()
{
getch();
closegraph();
}

搜索更多相关主题的帖子: 小女子 运行 感谢 
2005-12-17 00:51
快速回复:[求助]怎么运行不出来啊,谁可以帮忙看看啊,小女子万分感谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016722 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved