#include
#include
#include
typedef int datatype;
typedef struct tree{
char value[88];
struct tree *left,*right;
}tree;
void into_tree(tree *root,char value[])
{
tree *current;
tree **link;
link=&root;
while( (current=*link)!=NULL )
{
if( strcmp(current->value,value)==1)
link=¤t->left;
else
link=¤t->right;
}
current=malloc(sizeof(tree));
strcpy(current->value,value);
current->left=current->right=NULL;
*link=current;
}
void print_tree(tree *t)
{
if(t)
{
print_tree(t->left);
printf("%s\n",t->value);
print_tree(t->right);
}
}
main()
{struct tree *root=NULL;
char s[][88]={"ha","daf","dad"};
into_tree(root,s[0]);
print_tree(root);
}
为什么我插入s[0]后,root还是null?
怎么就没有改变root中value的值呢???
|