關(guān)于DeleteNode的一些疑問
void DeleteNode(){
if (this->pLChild != NULL){
this->pLChild->DeleteNode();
}
if (this->pRChild != NULL){
this->pRChild->DeleteNode();
}
if (this->pParent != NULL){
if (this->pParent->pLChild == this){
this==NULL;
}
if (this->pParent->pRChild == this){
this == NULL;
}
}
delete this;
}
//第三步的父節(jié)點(diǎn)判空? 完全可以改成這樣啊
if (this->pParent != NULL){
this == NULL;
}
2020-10-31
this = NULL與this->pParent->pLChild != NULL發(fā)生沖突,相當(dāng)于this->pParent->pLChild指向了空指針,發(fā)生異常
2020-10-31
好問題
2018-07-21
這樣是有問題的,本來只刪除左節(jié)點(diǎn)(該節(jié)點(diǎn)父節(jié)點(diǎn)的左節(jié)點(diǎn)),這樣會(huì)將右節(jié)點(diǎn)也一起刪除的!
2018-06-17
代碼被吞了花括號(hào)里邊是
this->pParent->pLChild = NULL;
pRChild同理
2018-06-17
首先你上面那段代碼就不是老師的源碼,老師那一部分的代碼是
其次this == NULL;這個(gè)語句就很令人費(fèi)解,我姑且先認(rèn)為是this = NULL;,現(xiàn)在的目的是把父節(jié)點(diǎn)中的pLChild或pRChild的“數(shù)據(jù)”改為NULL,那你把自己的指針變?yōu)榭崭蓡??父?jié)點(diǎn)的Child指針還是指向該節(jié)點(diǎn)啊,難道還會(huì)跟著變嗎?