vendredi 13 mars 2015

How to move from Child to Parent in a tree structure?



struct node
{
int data;
node *child;
node *sibling
};


I want to have a loop that moves from child to parent. If the root of a tree has 5 childs then starts from last child to root. meaning that the loop should move in a reverse way.


In fact, it could be easy if I have an array of childs, but what if I just have a child parent relationship, in that case, each child has a parent, So is it possible that I go from child to parents until I get to root.


thanks.




Aucun commentaire:

Enregistrer un commentaire