I am trying to make a binary tree program where each tree node contains a struct of 'inventory'.
I am currently getting an error in my insert function that causes compile to fail. The error I am getting is:
left of '.invPartNo' must have class/struct/union
type is 'inventory *'
did you intend to use '->' instead?
These are my structures:
//inventory definition
typedef struct inventory
{
char invName[36];
int invPartNo;
int invQOH;
float invUnitCost;
float invPrice;
}item;
//tree definition
struct btree {
item *data;
struct btree *left;
struct btree *right;
} ;
And this is my insert code, where I did use ->, so I don't understand the error I'm getting. Any help/explanation would be greatly appreciated.
struct btree *Insert(btree *node, inventory *i)
{
if(node == NULL)
{
btree *temp;
temp = (btree *)malloc(sizeof(btree));
temp->data = i;
temp->left = temp->right = NULL;
return temp;
}
if(i.invPartNo > node->data->invPartNo) //error here
{
node->right = Insert(node->right, i);
}
else if(i.invPartNo < node->data->invPartNo) //error here
{
node->left = Insert(node->left, i);
}
return node;
}