I know how to print a balanced binary tree, I'm just not sure how to print a tree with index values. By index values I mean if I print a list, I want to say that node X is the 5 node or whatever. I don't need to go back and use these index values like arrays to access an element. Just when I'm printing to console, do something like:
1 Node1
2 Node2
3 Node3
4 Node4
...and so on.
I've tried a few different options but my values grow exponentially or other weird things happen.
The function at it's basic:
1 2 3 4 5 6 7 8 9 10 11
void Print (node * x)
{
if ( x != NULL )
{
Print (x->left);
cout << ....data that needs to be printed
Print (x->right);
}
return;
}