My program crashes when I try to add a new node to binary search tree.
Crash message: Access violation reading location.
The line in xstring: return (compare(0, this->_Mysize, _Right._Myptr(), _Right.size()));
The Code:
main:
BSNode* bs = new BSNode("6");
bs->insert("2");
bs->insert("8");
The function where it crashes:
if (value.compare(_data) > 0)
{
if (this->isLeaf())
{
_right = new BSNode(value);
}
else
{
_right->insert(value);
}
}
else if (value.compare(_data) < 0)
{
if (this->isLeaf())
{
_left = new BSNode(value);
}
else
{
_left->insert(value);
}
}
It crashes at line 1, "if (value.compare(_data) > 0)".
More Code:
BSNode::BSNode(string value)
{
_data = value;
_right = NULL;
_left = NULL;
}
Thanks, Omer.