Thread: Please Help Me!!!!!!!!

  1. #1
    Unregistered
    Guest

    Unhappy Please Help Me!!!!!!!!

    How do I write the tree traverse inorder to look like the actually tree when I output it.
    The output will make the tree structure
    This is what I got so far:
    void InOrderTraversal(struct Node *parent)
    {


    if(parent->Left!= NULL)
    InOrderTraversal(parent->Left);
    cout << endl;
    cout <<( parent->Data);
    if(parent->Right!=NULL)
    InOrderTraversal(parent->Right);

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    If you want the output to look like the tree, then it'd be easier using a pre-order traversal.
    zen

  3. #3
    Unregistered
    Guest
    If I change to preorder than how would I write it so the output look like actually tree?
    Thanks!

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Think about it a little. gotoxy() can be used to great effect.
    The first thing you need to know is the height of the tree from root node to far left leaf node. if you know the height of the tree then you know where on the screen to print that far left node.Following a preorder traversal takes you to the right leaf node of the parent and again because this is the same distance from the root node you know where to print on the screen. Think about how to find the height of your tree.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed