一個項目我都以這種方式組成的樹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