Yesterday I wrote some functions to calculate connectivity between leafs and nodes...what it does is calculate what nodes are this node's (or leaf's) parent node (the node right above this node in the tree). It is supposed to visit every single node and leaf in the binary tree and set its parent. I *think* it works, but that's what I thought yesterday, and today it started to crash.
I've been trying to test it, but I want to see if anyone can conceptualize any errors that I might have missed.
Things I kept in mind when doing this that helped me:
-a leaf (the very end of a binary tree) has a negative index, the real index into the leaf array is -(index + 1)...the real index is the index you want to use when setting the leaf's parent node...but when you set a leaf's parent node you have hit the end of the tree and you want to stop recursing in that direction
-node's have a positive index, and if you are examining a node you are not at the end of the tree and you want to continue recursing
-Only want to call SetMeAsParent if the next section of the tree is in fact a node
I can't think of anything else to say that might help, if you have any questions to make what I am trying to do clearer please ask.
This has to do with game programming because I am using it in my BSP project
//Only calls SetMeAsParent if node
//Node index is the front or back of the previous node
void BSP::SetMeAsParent(int NodeIndex, int ParentIndex)
mpNodes[NodeIndex].parent = ParentIndex;
if(mpNodes[NodeIndex].front >= 0) //If my front is a regular node
SetMeAsParent(mpNodes[NodeIndex].front, NodeIndex); //set me as its parent
int i = -(mpNodes[NodeIndex].front + 1);
mpLeafs[i].parent = NodeIndex;
if(mpNodes[NodeIndex].back >= 0)
int x = -(mpNodes[NodeIndex].back + 1);
mpLeafs[x].parent = NodeIndex;
Like I said this 'seems' to work, I've been writing node indices to text files for an hour.