Dynamic Tree
-
Hi Experts, I need your help to solve a problem. Problem is to create a dynamic tree in memory. I have a node with 2 field 1. Self Record Number and 2. Parent Record Number I need to create a hierarchy (Tree) based on above information. Any node can come in any sequence. There is no rule defined for hirerchy. How to set the node at run time so that I can create a correct child-parent hierarchy?
-
Hi Experts, I need your help to solve a problem. Problem is to create a dynamic tree in memory. I have a node with 2 field 1. Self Record Number and 2. Parent Record Number I need to create a hierarchy (Tree) based on above information. Any node can come in any sequence. There is no rule defined for hirerchy. How to set the node at run time so that I can create a correct child-parent hierarchy?
The "parent" should point to the parent and the "self" should point to the sibling. But it is a very poor implementation, difficult to walk and maintain (who are the children of a given parent? you should keep a list of the "world" to scan!). Hierarchies normally requires more pointers: - to the parent - to the first child (and eventually to the last) - to the next sibling (and eventually the previous)
2 bugs found. > recompile ... 65534 bugs found. :doh:
-
Hi Experts, I need your help to solve a problem. Problem is to create a dynamic tree in memory. I have a node with 2 field 1. Self Record Number and 2. Parent Record Number I need to create a hierarchy (Tree) based on above information. Any node can come in any sequence. There is no rule defined for hirerchy. How to set the node at run time so that I can create a correct child-parent hierarchy?
john5632 wrote:
I have a node with 2 field 1. Self Record Number and 2. Parent Record Number
You can add your nodes to a vector, a linked list or a map. Then by definition you already have a tree, as long as you keep the constraint of not adding any loops, and keeping a single root node. It all depends on what you want to do with it in the end. If you need fast look-up, then look at Emilios suggestion above. Otherwise, go simple.