두 개의 이진 검색 트리가 같은지 테스트하는 코드를 작성했습니다.이진 검색 트리에서 이중 삭제 (?)
그러나 메모리를 할당 해제 할 때마다 액세스 위반 오류가 발생합니다. 그것을 살펴보면 메모리 할당 해제 기능에서 메모리 주소 0xfeefee에 액세스하고 있음을 알았습니다. Cell 소멸자 함수에서 액세스 위반이 발생합니다.
또한 실제로이 기능이 작동하는지 알 수는 없지만 실제로 도움을 요청하는 것은 아닙니다. 도움을받을 수는 있지만 여전히 도움이 될 것입니다.
할당 해제 기능 :
~Cell(void) {
if (left) { delete left; }
if (right) { delete right; }
}
기능 :
bool BST::isEqualTo(const BST& that) const{
if(root <= 0 && that.root <= 0){
return true;
}else if(root <= 0 || that.root <= 0){
return false;
}
if(root->val != that.root->val){
false;
}
/*Cell* saved_node1 = new Cell(*root);
Cell* saved_node2 = new Cell(*that.root);*/
BST a, b, c, d;
a.root = root->left;
b.root = that.root->left;
c.root = root->right;
d.root = that.root->right;
if(a.isEqualTo(b) && c.isEqualTo(d)){
/*a.root = saved_node1;
b.root = saved_node2;
c.root = saved_node1;
d.root = saved_node2;*/
return true;
}
return false;
}
트리 소멸자 :
void BST::destroy(void) {
length = 0;
delete root;
root = nullptr;
}
'BST :: root' 변수의 타입은'Cell *'입니다. 맞습니까? 또한'~ BST'를 보여주십시오. – soon
예 루트는 Cell * 데이터 유형입니다. – kir
@ user2280704 : BST 소멸자를 표시 할 수 있습니까? – Grzegorz