I'm having problems getting this display to work.
I feel my logic is off.
Below use level order traversal to place the data from the node into a temporary storage array.
Code:
binaryTreeArrayPtr[levelCounter++]=p->info;
Below is also in my level order traversal. This is how I attempt to put NULL values into my array for holder locations
Code:
if (p->llink==NULL)
{
binaryTreeArrayPtr[(2*nodeCounter)+1]=NULL;
}
if (p->rlink==NULL)
{
binaryTreeArrayPtr[(2*nodeCounter)+2]=NULL;
}
Next I use this to display the details of the array in binary tree format.
Code:
//I want to try to shrink this by a using a loop
cout<<setw(40)<<binaryTreeArrayPtr[0]<<endl<<endl<<endl;
cout<<setw(35)<<"/"<<setw(10)<<"\\"<<endl<<endl;
cout<<setw(32)<<binaryTreeArrayPtr[1]<<setw(16)<<binaryTreeArrayPtr[2]<<endl<<endl;
cout<<setw(28)<<"/"<<setw(6)<<"\\"<<setw(12)<<"/"<<setw(6)<<"\\"<<endl<<endl;
cout<<setw(26)<<binaryTreeArrayPtr[3]<<setw(10)<<binaryTreeArrayPtr[4]<<setw(8)<<binaryTreeArrayPtr[5]
<<setw(10)<<binaryTreeArrayPtr[6]<<endl<<endl;
cout<<setw(24)<<"/"<<setw(3)<<"\\"<<setw(7)<<"/"<<setw(3)<<"\\"<<setw(6)<<"/"<<setw(3)
<<"\\"<<setw(7)<<"/"<<setw(3)<<"\\"<<endl<<endl;
cout<<setw(22)<<binaryTreeArrayPtr[7]<<setw(6)<<binaryTreeArrayPtr[8]<<setw(5)<<binaryTreeArrayPtr[9]
<<setw(5)<<binaryTreeArrayPtr[10]<<setw(4)<<binaryTreeArrayPtr[11]<<setw(5)<<binaryTreeArrayPtr[12]
<<setw(5)<<binaryTreeArrayPtr[13]<<setw(6)<<binaryTreeArrayPtr[14]<<endl;
I'm having problems with it displaying correctly.
see the below output.
Code:
//program display
Tree nodes in levelorder: 5 2 7 1 3 6 8 4 9
Number of Nodes: 9
Number or Leaves: 4
5
/ \
0 0
/ \ / \
1 3 6 8
/ \ / \ / \ / \
4 9-842150451-842150451-842150451-842150451-842150451-8
42150451
Press any key to end
I was trying to see if writing all the code out would clue me into a loop or some kind of algorithm that would me to shrink the code.
I have only found that i have an issue with my logic, and that there is no method to the madness.