How do I get the code to say at Insertion:
- Root Node is Added (1st insert),
- Node Added to Left (2nd insert),
- Node Added to Right (3rd insert),
- Node Added to Right (4th insert),
right below when each node is added.
There's something wrong with my display. I can't get it to run. Code is as below in the link. I need to display the tree structure from the result of all insertion.
void BinarySearchTree::display(tree_node *ptr, int level)
{
int i;
if (ptr != NULL)
{
display(ptr->right, level+1);
cout<<endl;
if (ptr == root)
cout<<"Root->: ";
else
{
for (i = 0;i < level;i++)
cout<<" ";
}
cout<<ptr->data;
display(ptr->left, level+1);
}
}
case 5: cout<<"Display BST:"<<endl;
b.display(tmp,1);
cout<<endl;
break;