二叉树的基本问题,高手请指点.
#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)