一个项目我都以这种方式组成的树n元:搜索在N叉树
struct n_tree{
struct list *adj;
};
struct list{
struct n_tree *child;
struct list *next;
int key;
};
我如何可以搜索一个项目? 我已经实现了这个功能,但它不工作......谢谢!
struct list *find(struct list *root, int key){
if(root){
find(root->next,key);
if (root != NULL){
if(root->key == key){
return root;
}
else if(root->child != NULL){
return find(root->child->adj,key);
}
}
}
}
如何分割'n'节点中的关键范围?我的意思是,用二叉树很简单:“key”下面的所有东西都是左边的,其他的东西都在右边。但是''n'元素不是很清楚。 – dasblinkenlight
你做了一个递归调用find(root-> next,key);'但是不要使用返回的结果。那你为什么打这个电话? – CiaPan
你说你有*'这样构成的树'*,但你实际上并没有显示任何*'方式'*。你刚刚展示了数据结构,但没有解释它们的含义:列表以某种方式排序?与'next'链接的列表中'键'之间的关系是什么?列表项中的“key”与“子”子树中的“key”之间的关系是什么? – CiaPan