自己编的c语言建立二叉树的代码,运行时出错了,自己找不到错误,求大神帮忙,指点,急.
#include
#include
typedef struct tnode Tnode;
struct tnode
{
Tnode *left;
Tnode *right;
int data;
};
Tnode *new_tnode(int data)
{
Tnode *new = malloc(sizeof(Tnode));
new->left=NULL;
new->right=NULL;
new->data=data;
return new;
}
void insert(Tnode *root,Tnode *tree)
{
if(root==NULL)
{
tree=root;
return;
}
if(root->datadata)
{
tree->left=root;
insert(root,tree->left);
}
else if(root->data>tree->data)
{
tree->right=root;
insert(root,tree->right);
}
}
void printout(Tnode *tree)
{
if(tree==NULL)
{
return;
}
printf("%d",tree->data);
printout(tree->left);
printout(tree->right);
}
int main()
{
Tnode *tree=NULL;
int i;
int data;
for(i=0;i<10;i++)
{
scanf("%d",&data);
insert(new_tnode(data),tree);
}
printout(tree);
return 0;
}