问题遇到的现象和发生背景
写的二叉树排序和输出。一直无法编译通过,找不到问题所在,感谢指教
问题相关代码,请勿粘贴截图
#include<stdio.h>
#include<stdlib.h>
//#include"treefunction.h"
typedef int Element;
typedef struct Tnode
{
Element data;
struct Tnode *right;
struct Tnode *left;
}Tnode;
Tnode *insert(Tnode *root,Tnode *p)
{
if(root==NULL)
{
return p;
}
else
{
if(root->datadata)
{
root->right=insert(root->right);
}
if(root->data>p->data)
{
root->left=insert(root->left);
}
return root;
}
void p1_printf(Tnode *root)
{
if(root==NULL)
{
return ;
}
else
{
printf("%d",root->data);
p1_printf(root->left);
p1_printf(root->right);
}
}
void p2_printf(Tnode *root)
{
if(root==NULL)
{
return ;
}
p2_printf(root->left);
printf("%d",root->data);
p2_printf(root->right);
}
void p3_printf(Tnode *root)
{
if(root==NULL)
{
return ;
}
p3_printf(root->left);
p3_printf(root->right);
printf("%d",root->data);
}
int main()
{
int d;
Tnode *root=NULL;
scanf("%d",&d);
while(1)
{
if(d==0)
{
break;
}
Tnode *p=malloc(sizeof(*p));
p->data=d;
p->right=NULL;
p->left=NULL;
root=insert(root,p);
p1_printf(root);
p2_printf(root);
p3_printf(root);
}
return 0;
}
运行结果及报错内容
avl_tree.c: In function ‘insert’:
avl_tree.c:28:21: error: too few arguments to function ‘insert’
root->right=insert(root->right);
avl_tree.c:18:8: note: declared here
Tnode *insert(Tnode *root,Tnode *p)
avl_tree.c:32:24: error: too few arguments to function ‘insert’
root->left=insert(root->left);
avl_tree.c:18:8: note: declared here
Tnode *insert(Tnode *root,Tnode *p)
avl_tree.c:106:1: error: expected declaration or statement at end of input
}