Thread: think recursevely this problem

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    think recursevely this problem

    a balanced tree is if its the difference between the left subtree
    and the right subtree is smaller than 2.

    i need to build a function which return 1 if the tree is balanced
    and 0 if else.

    how to store the height of each node from the ground?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Try one of the various data types which store numbers.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Well you can create a height recursive function to determine the height.

    Code:
    int height (link t)
    {
        int left,right;
        if (t == NULL) return -1;
        left = height(t->l); 
        right = height(t->r);
        if (left  > right)
          return left + 1; 
        else return right +1;
    }

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Or you can just wait around and someone will do everything for you AGAIN!


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM