I have a tree n-ary composed in this way:
struct n_tree{
struct list *adj;
};
struct list{
struct n_tree *child;
struct list *next;
int key;
};
How i can search an item? I have implemented this function, but it does not work... Thanks!
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);
}
}
}
}
Before looking at the children, you need to look at the local node, since that's how you actually find things and end the recursion.
Also, doing a recursive call and ignoring the return value is pointless (unless there's an "out-parameter", which there isn't here). So don't do that.