Thread: comparing subtrees question..

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

    comparing subtrees question..

    i nee to write a function which desides if the right subtree has more red nodes then the left sub tree

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define FALSE 0
    #define TRUE 1
    #define RED 1
    #define BLUE 2
    
    typedef struct {
        int key;
        int color;
    }Data;
    
    
    typedef struct TreeNode{
        struct TreeNode *father;
        struct TreeNode *left;
    	struct TreeNode *right;
    	Data TreeNode_info;
    }TreeNode;
     
    int main()
    {
    
    	return 0;
    }
    
    int isRedRight(TreeNode * root)
    {
      if (root==NULL)
      {
        return 0;
      }
      if ((root->TreeNode_info==RED)&&(root->left==NULL)&&(root->left==NULL))
      {
        return 1;
      }
      else
      {
          if (isRedRight(root->right)>isRedRight(root->left))
    	   {
              return 1; 
    	   }
      }
    
    }
    i cant return a number of nodes because in this is a "boolean " function
    it return only true 1 or false 0
    ??

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Without getting bogged down by coding, first try to come-up with an algorithm for doing the task.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    write another function first - that counts number of nodes in the subtree
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Comparing Arrays question
    By taugust7 in forum C++ Programming
    Replies: 36
    Last Post: 04-14-2009, 12:29 PM
  2. string comparing question..
    By transgalactic2 in forum C Programming
    Replies: 4
    Last Post: 03-23-2009, 02:22 PM
  3. A quick question on comparing characters.
    By Nutcasey in forum C Programming
    Replies: 5
    Last Post: 12-19-2003, 03:26 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Replies: 7
    Last Post: 04-13-2003, 10:53 PM