0

this is my struct

struct CropType
{
        string crop;
        string farmer;
        string color;
        string order;
};

CropType myCrop;

and this is my tree

struct TreeNode
{
        CropType info;
        TreeNode* left;
        TreeNode* right;
};

how do i compare a string within my struct like crop to a node in my tree

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Jayrrus
0

Do you mean how do you compare the value of crop at one node with the value of crop at another given node?

It's as simple as it sounds....

aNode->info->crop == anotherNode->info->crop

Chris

0

Do you mean how do you compare the value of crop at one node with the value of crop at another given node?

It's as simple as it sounds....

aNode->info->crop == anotherNode->info->crop

Chris

thanx chris

now my other problem is that this sruct is being inserted into a tree via void insert function

void Insert(TreeNode*& tree, CropType &myCrop)
{
          {
               
                Treenode *current;

               if(tree==NULL)
               {
                    current=new Treenode;
                    current = tree;
                    current->left = NULL;
                    current->right = NULL;
                    current->data = myCrop.crop;
                    current->data  = myCrop.farmer;
                    current->data  = myCrop.order;
                    current->data  = myCrop.color;
               }
               else if( current->data->myCrop.crop < tree->data->crop)
               {
                        current->left=insert(tree->left, myCrop);
               else
               tree->right=insert(tree->right, myCrop);

               return(tree);
          }

is this right??

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.