Subj : Re: How to deal with Tree with several branchs? To : comp.programming From : Thad Smith Date : Sat Jul 23 2005 09:22 pm Davy wrote: > My program deal with a several level tree with several branchs. The > amount of branchs from father node is not known. So I want to creat a > tree with dynamic branchs. > > Now I use the structure: > typedef struct gnodes > { > int level; //tree level > struct gnodes* pfather; > struct gnodes* pbrother; > struct gnodes* pchild; > struct gnodes* puncle; > } gnode; Is puncle redundant? What is it used for? > The child pointer link one by one form a chain, something like: > Father(i)->Child(1)->Child(2)->...->Child(n-1)->Child(n). > But I can not search child randomly. > > How to design a better structure? That depends on what you want to use your data structure for. The links that you have should allow you to move up and down the tree and access siblings. If you want to directly access the third child from the parent node, for example, you can allocate an array of child pointers, rather than relying on the linked list. How important that is depends on your application. Thad .