[求助]能帮我运行一下看错误出现在那里吗
#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);
}