亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

關于searchnode函數的一點解析,這里想了好長時間才轉過來!

?

Node *Node::SearchNode(int nodeindex)

{

? ? if(this->index==nodeindex)//查找當前節點

? ? ? ? return this;?

? ? if(this->pLChild!=NULL)//查找左子節點

? ? {

? ? ? ? if(this->pLChild->index==nodeindex)

? ? ? ? ? ? return this->pLChild;?

else if (this->pLChild->SearchNode(nodeindex))

return this->pLChild->SearchNode(nodeindex);


else//查找右子節點

{

if(this->pRChild!=NULL)

{

if(this->pRChild->index==nodeindex)

return this->pRChild;

if(this->pRChild->SearchNode(nodeindex))

return this->pRChild->SearchNode(nodeindex);

}

}

? ? }

? ? return NULL;

}

其實最簡單的方法就是仿照遍歷函數,搜索只是多了一個限定條件;

這里searchnode函數的返回值是node類型;

只能有一個return null ;

正在回答

2 回答

我覺得這代碼有問題吧,視頻中刪除的最右邊那個節點,按照這個搜尋方法,當遍歷到最左邊這個節點時,此時this指的是最左邊的指針,這樣他肯定不會進入第二個if語句

0 回復 有任何疑惑可以回復我~

well


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

關于searchnode函數的一點解析,這里想了好長時間才轉過來!

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號