Print Tree

This is my tree(without the underscores):
_________5
________/ \
_______4___8
______/____/ \
____11___13__4
____/ \________\
___7___2________1
I'm required to print it in this format.
Currently I have this code:
1
2
3
4
5
6
7
8
9
10
11
void print_tree_structure(BinaryTree *bt, int spaces)
{
  if(bt != NULL)
  {
    print_tree_structure(bt->right(), spaces + 5);
    for(int i = 0; i < spaces; i++)
      	cout << ' ';
    	cout << "   " << bt->getData() << endl;
    print_tree_structure(bt->left(), spaces + 5);
  }
}

It works fine enough but it prints zeros for the leaf nodes. I've tried putting an if condition if(bt->getData() != 0) before the cout and it works but the 4 moves up to the 5. Any ideas on how to correct this?

Thanks
Last edited on
It looks good
then zero must always be the return value from bt->getData()

lets see that functions code...
Topic archived. No new replies allowed.