for(node* it=list->head;it!=NULL;it=it->next)
{
if(it->parent!=NULL)
it->parent->addToChildrenList(it);
}
or
Hash the nodes based on their parent pointer values. Then iterate through the list and for each node, get the hash value of its own pointer. All the nodes that are in the list present in that hash slot are its children
No comments:
Post a Comment