Binary tree display

This is a discussion on Binary tree display within the C Programming forums, part of the General Programming Boards category; How can I display a binary tree showing its real structure like. Can any one suggest an algorithm for this ...

  1. #1
    Logic Programmer logicwonder's Avatar
    Join Date
    Nov 2005
    Location
    Kerala, India
    Posts
    52

    Question Binary tree display

    How can I display a binary tree showing its real structure like.
    Can any one suggest an algorithm for this purpose

    Code:
                                         5
    
                               3                  8
    
                          1        4        6        9
    L GIK wins!!!
    Salutes from logicwonder
    Enjoy programming

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Check out a Breadth First Algorithm

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    First thing you probably need is something to work out the height of the tree, in order to work out how far to indent the root node.

    Then something to take that base level indentation, and with each L or R move, subtract or add an appropriate level of indentation based on the current depth of the traversal.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple binary search tree?
    By sybariticak47 in forum C++ Programming
    Replies: 8
    Last Post: 08-09-2007, 03:53 PM
  2. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  3. best STL method to implement a binary tree
    By MatthewDoucette in forum C++ Programming
    Replies: 8
    Last Post: 06-16-2006, 07:08 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. display tree data in binary tree format
    By xddxogm3 in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 11:47 PM

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