You have a tree. Most of the nodes have only one child and no siblings.
Index 0 is the root
Index 2 has children 3, 7, 11, and 46. Thus 3 is the first child of 2 and there is a list: 3->7->11->46
3 has 4 as child. 4 has 5 as child. 5 has 6 as child. 6 has no children.
7 has 8 as child. 8 has 9 as child. 9 has 10 as child. 10 has no children.
11 has 12 as child. 12 has 13 as child. 13 has 14 as child.
14 has children 15, 20, and 33.
15 has children 16, 17, 18, and 19.
If you want to create the tree by iterating the parentInx, then you do need function that adds
a node to the tree:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
void insert( Bone * tree, int newindex, int parent )
{
// search from tree a node X that has index 'parent' (could be a recursive function)
if ( nullptr == X->child )
{
// add new node with newindex as X->child
}
else
{
Bone * Y = X->child;
Bone * Z = Y->sibling;
while ( Z ) {
Y = Z;
Z = Y->sibling;
}
// add new node with newindex as Y->sibling
}
}
|