print a binary tree!

This is a discussion on print a binary tree! within the C Programming forums, part of the General Programming Boards category; hi!! I am looking for a way to print a binary tree as a binary tree,with a root and nodes.so ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    2

    Cool 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?
    Last edited by basilis; 08-26-2001 at 05:16 PM.

  2. #2
    junior member mix0matt's Avatar
    Join Date
    Aug 2001
    Posts
    144
    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
    THIS IS NOT JUST A CHRONICLING OF THINGS WE HAVE DONE IN THE PAST BUT OUR RISE TO POWER.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Tree Search
    By C++Newbie in forum C++ Programming
    Replies: 7
    Last Post: 04-05-2011, 02:17 AM
  2. Binary Tree
    By Ideswa in forum C Programming
    Replies: 12
    Last Post: 10-25-2007, 01:24 PM
  3. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 03:56 PM
  4. searching and insertion in a binary search tree
    By galmca in forum C Programming
    Replies: 1
    Last Post: 03-26-2005, 05:15 PM
  5. print a binary tree!
    By basilis in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-26-2001, 08:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21