二叉树的基本问题,高手请指点.

jongsuny 2008-01-03 07:25:46
#include <stdlib.h>
#include <stdio.h>
#define NULL 0
struct tree
{
struct tree *left;
int data;
struct tree *right;
};
typedef struct tree treenode;
treenode *b_tree;
b_tree insert_node(b_tree root,int node)
{
b_tree newnode;
b_tree currentnode;
b_tree parentnode;
newnode=(b_tree) malloc (sizeof(treenode));
newnode->data=node;
newnode->right=NULL;
newnode->left=NULL;
if(root==NULL)
return newnode;
else
{
cuurentnode=root;
while(currentnode!=NULL)
{
parentnode=currentnode;
if(currentnode->data>node)
currentnode=currentnode->left;
else
currentnode=currentnode->right;
}
if(parentnode->data>node)
parentnode->left=newnode;
else
parentnode->right=newnode;
}
return root;
}
b_tree create(int *data,int len)
{
b_tree root=NULL;
int i;
for(i=0;i<len;i++)
root=insert_node(root,data[i]);
return root;
}
void print(b_tree root)
{
b_tree pointer;
pointer=root->left;
printf("print left sub tree node of root!:\n");
while(pointer!=NULL)
{
printf("[%2d]\n",pointer->data);
pointer=pointer->left;
}
}
void main()
{
b_tree root=NULL;
int i,index;
int value;
int nodelist[20];
printf("\n please input the elements of tree[exit for 0]\n");
index=0;
scanf("%d",&value);
while(value!=0)
{
nodelist[index]=value;
index=index+1;
scanf("%d",&value);
}
root=create(nodelist,index);
print(root);
}


d:\我的文档\数据结构\树\187.cpp(12) : error C2146: syntax error : missing ';' before identifier 'insert_node'
d:\我的文档\数据结构\树\187.cpp(12) : error C2501: 'b_tree' : missing storage-class or type specifiers
d:\我的文档\数据结构\树\187.cpp(12) : error C2040: 'b_tree' : 'int' differs in levels of indirection from 'struct tree *'
d:\我的文档\数据结构\树\187.cpp(12) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

187.exe - 1 error(s), 0 warning(s)
...全文
54 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
heibai_xiaoer 2011-11-22
  • 打赏
  • 举报
回复
由衷的感谢!!!
jongsuny 2008-01-03
  • 打赏
  • 举报
回复
嘿嘿..是啊..
研究了2天都放弃了,
今天又起来研究这个..
终于明白了..少了个typedef...
p0303230 2008-01-03
  • 打赏
  • 举报
回复
恭喜
lj860603 2008-01-03
  • 打赏
  • 举报
回复
解决了?呵呵。
jongsuny 2008-01-03
  • 打赏
  • 举报
回复
快晕死了......5555555555555555
第 11 行..
typedef treenode *b_tree;
就差一个 typedef ...
研究了 半天都没弄出来的...5555555
疯了///

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧