-
print a binary tree!
hi!!
I am looking for a way to print a binary tree as a binary tree,with a root and nodes.so when you look at the screen you will see a binary tree not some data in line!
thanks !!!!
i am looking forward for an answer!
FOR mixOmatt!one way is as shown below,but the fuction has a logic bug!and the results are not printed as i expected!!
void viewtree(struct node *t,int x,int y)
{
if(t==NULL)return;
gotoxy(x,y);
printf("%d",t->key);
viewtree(t->left,x-4,y+1);
viewtree(t->right,x+4,y+1);
}
i am waiting for your reply!
you dig?
-
if you know how to print the contents of the binary tree in LNR order (left-node-right), your problem becomes a question of simple formatting. However, large trees are going to be difficult to keep on the screen...
I don't really feel like giving you an answer since you've shown no effort. You really can't expect someone to do all of it for you. That wouldn't be fair to "rest of the class". Besides this is something you should really understand, and having me do it for you would really only hurt you. You dig?
HINT: If you can't think through it yourself, search for binary trees and recursion on google
btw: LNR means
Code:
node
/ \
left right