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

Recommended Answers

All 2 Replies

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

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??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.