Thread: Simple binary tree height function.

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    27

    Simple binary tree height function.

    All I need is a simple function that will return the height of the tree. Can someone please tell me what's wrong with this code...

    Code:
    int bt::tree_height(const node *mytree)
    {
      if(mytree == NULL)
      {
       return 0;
      }
      else
      {
        return 1 + maximum(tree_height(mytree -> left), tree_height(mytree -> right));
      }
    }
    
    int bt::maximum(int left, int right)
    {
      if(left >= right)
        return left;
      else
        return right;
    }
    I've done tests and the result is wrong.
    Last edited by noodle24; 04-12-2007 at 07:25 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Why do you think it is wrong?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  2. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  3. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM