当我使用整数现在 我想插入字符串所以这段代码是可以正常使用的数据结构实现我改变了比较,STRCOMP及其不woorking任何帮助赞赏 链接的全部代码http://pastebin.com/6j1haZRF树木在C
struct node * insert(struct node *root, char x[])
{
if(!root)
{
root=(struct node*)malloc(sizeof(struct node));
root->data = x;
root->left = NULL;
root->right = NULL;
return(root);
}
if((a=strcmp(root->data,x))>0){
root->left = insert(root->left,x);
}
else
{
if(strcmp(root->data,x)<0)
root->right = insert(root->right,x);
}
return(root);
}
当你说它已停止工作,你的意思是它运行,但没有得到你期望的结果?你有任何错误? – xagyg 2013-05-01 23:49:13
它只为第一次插入而运行 – 2013-05-02 14:28:03