Original Post
every time i go to start implementing a tree i always get problems and it is always to do with pointers at some point.
Here is how if defined my tree
i am quite sure that doesn''t have any problems.
But here i have a function for inserting a new item into the tree
but i get 7 errors. they are all like this error
C2227: left of ''->data'' must point to class/struct/union
Can someone please help.
typedef int ITEM_TYPE;
struct BSTreeNode
{
ITEM_TYPE data;
struct TreeNode *left;
struct TreeNode *right;
};
typedef struct BSTreeNode *BS_TREE;
bool InsertChild(BS_TREE *tree, ITEM_TYPE item)
{
if(tree = NULL)
{
tree = new BS_TREE;
tree->data = item;
tree->left = NULL;
tree->right = NULL;
}
else
if(item = tree->data)
{
return false;
}
else
if(item < tree->data)
{
InsertChild(tree->left, item);
}
else
{
InsertChild(tree->right, item);
}
return true;
};