바이너리 검색 트리에서 삭제하려고하고 디버거 에서이 오류가 계속 발생하고이를 해결하기 위해 무엇을해야할지 모르겠습니다. 이 코드가 맞습니까?이진 검색 트리에서 삭제 하시겠습니까?
프로그램 수신 신호 EXC_BAD_ACCESS, 메모리에 액세스 할 수 없습니다. 이유 : KERN_INVALID_ADDRESS 주소 : 0x0000000000000000 0x00007fff8cc17fe2 표준에가 : 문자열 :: 비교()
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;
}
}
'address : 0x0000000000000000'은 NULL 포인터 역 참조 일 수 있습니다. 디버거를 사용하여 추적하십시오. –