I am trying to write a function to print a binary tree as graph. Preorder print is chosen and the code I come out is:
I want the tree to look something like that.Code:void preorder_print(root*tree){ if (tree!=NULL){ printf(" %d\n",tree->key); printf("\t"); preorder_print(tree->left); printf("\n"); preorder_print(tree->right); } }
5
├3
│├2
│└5
└7
├
└8
I know that I can use ASCII characters but
my problem is how to find the right tab to print each line (vertical tree graph would be fine).
1.any proposals on that.
2.any opinions about using the goto??