| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 600 人关注过本帖
标题:[求助]能帮我运行一下看错误出现在那里吗
只看楼主 加入收藏
shashaxia
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-12-11
收藏
 问题点数:0 回复次数:5 
[求助]能帮我运行一下看错误出现在那里吗
#include "stdio.h"
#include "conio.h"
#define NULL 0
struct node
{
int data;
struct node *lchild;
struct node *rchild;
struct node *parent;
}*root,*p,*tree,*f,
main()
{
void inorder(struct node *root);
void search(struct node *root,struct node *tree);
int find(struct node *root,int x,struct node *f);
int insert(int i,struct node *p,int x);
char c;
int i,j,x;
do
{
root=(struct node *)malloc(sizeof(struct node));
printf("\n\nplease enter root's node(-1 to end)");
if(scanf("%d",&root->data)&&root->data==-1)
printf("\n\nThe linary tree has no any nodes");
else
{
root->parent=NULL;
root->lchild=NULL;
root->rchild=NULL;
printf("\n\nPlease enter tree's node(-1 to end)\n");
do
{
tree=(struct node *)malloc(sizeof(struct node));
scanf("%d",&tree->data);
if(tree->data!=-1)
{
tree->parent=NULL;
tree->lchild=NULL;
tree->rchild=NULL;
search(root,tree);
if(p->data<tree->data)
p->rchild=tree;
else if(p->data>tree->data)
p->lchild=tree;
else
free(tree);
tree->parent=p;
}
}while(tree->data!=-1);
printf("\n\nCreating binary tree is:\n");
inorder(root);
}
printf("\n\nDo you want to create a new tree again? (Y,y(Yes) or N,n(No))");
}while((scanf("%c",&c)&&c=='Y')||(scanf("%c",&c)&&c=='y'));
printf("\n enter the x to insert:");
scanf("%d",&x);
printf("%d",x); 到这里就运行不下去了 ^_^
f=NULL;
i=find(root,x,f);
j=insert(i,root,x);
if(j==0)
printf("\nx is already in the tree");
else
{
printf("\nthe new tree is :");
inorder(root);
}
}
void inorder(struct node *root)
{
if(root!=NULL)
{
inorder(root->lchild);
printf("%d\t",root->data);
inorder(root->rchild);
}
}
void search(struct node *root,struct node *tree)
{
if((root->data<tree->data)&&(root->rchild!=NULL))
search(root->rchild,tree);
else if((root->data>tree->data)&&(root->lchild!=NULL))
search(root->lchild,tree);
else
p=root;
}
int find(struct node *root,int x,struct node *f)
{
if(root==NULL)
{
p=f;
return(0);
}
else if(root->data==x)
{
p=root;
return(1);
}
else if(root->data>x)
return(find(root->lchild,x,root));
else
return(find(root->rchild,x,root));
}
int insert(int i,struct node *p,int x)
{
struct node *s;
if(i==0)
{
s=(struct node *)malloc(sizeof(struct node));
s->data=x;
s->lchild=s->rchild=NULL;
if(p==NULL)
root=s;
else if(p->data>x)
p->lchild=s;
else
p->rchild=s;
return(1);
}
else
return(0);
}
搜索更多相关主题的帖子: node struct int root void 
2005-12-15 02:33
沉默的羔羊1013
Rank: 1
等 级:新手上路
帖 子:72
专家分:0
注 册:2005-12-10
收藏
得分:0 
可以运行阿,你在main()函数的结尾处加个getch();就行了
2005-12-15 12:43
shashaxia
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-12-11
收藏
得分:0 
还是不行啊,我的QQ是107238867
方便联系啊
2005-12-15 12:52
shashaxia
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-12-11
收藏
得分:0 
行了 ,谢啦
2005-12-15 15:03
沉默的羔羊1013
Rank: 1
等 级:新手上路
帖 子:72
专家分:0
注 册:2005-12-10
收藏
得分:0 
怎麽弄好的?是加个getch(); 就可以了吗
2005-12-15 15:40
shashaxia
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-12-11
收藏
得分:0 
en ,是啊
2005-12-15 22:40
快速回复:[求助]能帮我运行一下看错误出现在那里吗
数据加载中...
 
   



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

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