我正在尝试从二叉搜索树中删除并在调试器中不断收到此错误,并且不确定如何纠正它。这段代码正确吗?
程序收到信号 EXC_BAD_ACCESS,无法访问内存。原因:KERN_INVALID_ADDRESS 地址:0x0000000000000000 0x00007fff8cc17fe2 in std::string::compare ()
void remove( const Comparable & x, BinaryNode *& t )
{
if (t != NULL)
{
if(t->element.find(x) != std::string::npos)
{
if( t->left != NULL && t->right != NULL ) // Two children
{
t->element = findMin( t->right )->element;
remove( t->element, t->right);
}
else
{
BinaryNode *oldNode = t;
t = ( t->left != NULL ) ? t->left : t->right;
delete oldNode;
cout << "Successly deleted!" << endl;
}
}
if(x < t->element)
{
remove(x, t->left);
}
else
{
remove(x, t->right);
}
}
else
{
cout << x << "<-could not delete?" << endl;
}
}