I am getting an "invalid operands to binary" error for the lines "pp->element == value" and "pp->left->element > value".
int insert(NodeT **pp, Element value) { if (pp->element == value) { return 0; } else if (pp->left->element > value) { pp->left = allocateNode(value); } else { pp->right = allocateNode(value); } }
According to my knowledge,as the code is not completely given,I can say that either of the reasons:
1.)
When comparing two values, they must be of the same type. This is because pointer arithmetic in C is based on the size of the pointers, so for example if you subtract char* from int* you have a 1-byte object and a 4-byte object, and so there is no way for the compiler to know whether the result should be in 1-byte units or 4-byte units.
I realize your two values are both single bytes, but it's still not allowed in standard C (which makes no assumptions that objects of different types would be stored in the same area, etc.).
2.)In pp->element the "element" would not be of type Nodet or else it is not a pointer.
Get Answers For Free
Most questions answered within 1 hours.