comparing subtrees question..

This is a discussion on comparing subtrees question.. within the C Programming forums, part of the General Programming Boards category; i nee to write a function which desides if the right subtree has more red nodes then the left sub ...

  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,047
    Without getting bogged down by coding, first try to come-up with an algorithm for doing the task.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,459
    write another function first - that counts number of nodes in the subtree
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 02: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

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