Binary Tree Help

This is a discussion on Binary Tree Help within the C++ Programming forums, part of the General Programming Boards category; I have written a binary tree program in C++ which prints out the contents of the tree in order. I ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    5

    Binary Tree Help

    I have written a binary tree program in C++ which prints out the contents of the tree in order. I now need a function thats prints it out in descending order. I am having a some trouble with this so any help would be greatly appreciated.

    Many Thanks


    Temden

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    >> I am having a some trouble with this

    Trouble with what exactly?

    First post what you already have, then somenone may be able to help you.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    5
    Code:
     void print2(struct tree* root) {   
     struct tree  *lowertree, *highertree;
       highertree=root->higher;
       lowertree=root->lower;
       if (lowertree)
          print(lowertree);
           if (root->value != NULL)
            cout<<root->value<<endl;
       if (highertree)
          print(highertree);
               }


    This Code prints the tree in order how would I change this to make it print the opposite way round decending order.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Swap the calls over, so you print higher first?
    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.

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    5
    Thanks so much I had switched the calls but ive just realised instead of the function calling itself it calls another function that prints inorder.

    Thanks for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2006, 10:07 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 08:40 PM
  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. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM

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