Thread: FAQ Printing a binary tree?? (C)

  1. #1

    Question Printing a binary tree??

    I am currently working on a function that accepts the root for a binary tree and prints out the tree structure with the numbers. I want to know where do I begin. Do I need to count the height of the tree or what... I need some help....

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > I want to know where do I begin.
    At the root of the tree

    > Do I need to count the height of the tree or what
    That would depend on how you choose to represent the tree when you've printed it.

    If its just a text dump, no formatting is required

    But if it's a nice graphical thing, then more work is required.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    I want a graphically output:
    25 30
    ......and such

  4. #4
    that didnt come out right....cuz I guess this forum doesnt display the spaces. I want a graphically tree with the corresponding numbers.

  5. #5


    i still need some help???what this printing of a tree structure.....

  6. #6
    Registered User
    Join Date
    Sep 2001
    Still not too sure what your asking, but here goes...

    1) The generic treeprinting program
    void printtree(node * tree)
     if (tree != NULL)
      print (tree -> info); // Not a real command
      printtree (tree -> left);
      printtree (tree -> right);
    2) If you want a graphical tree, might I suggest something using ASCII characters 179, 192, and 195? You know, just do those to draw lines from nodes to their children, with each node being on a different line. It's not spaced out as a tree diagram usually is, but it does have connectivity lines, which is the importatnt thing, personally.
    Callou collei we'll code the way
    Of prime numbers and pings!

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, 01:17 AM
  2. determine if tree is strictly binary bst
    By ashir30000 in forum C++ Programming
    Replies: 3
    Last Post: 02-25-2010, 01:51 PM
  3. Binary Search Tree - one last question
    By tms43 in forum C++ Programming
    Replies: 2
    Last Post: 11-14-2006, 03:58 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Tutorial review
    By Prelude in forum A Brief History of
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM