課程
/后端開發
/C++
/數據結構探險之樹篇
是不是有錯
????
2017-03-15
源自:數據結構探險之樹篇 6-2
正在回答
后來改了,前面的是有錯,沒考慮周全
Node *Node::searchNode(int nodeIndex)
{
Node *temp=NULL;
if(this->index==nodeIndex) ?return this;
if(this->pLChild!=NULL)
if(this->pLChild->index==nodeIndex)
return this->pLChild;
else
temp=this->pLChild->searchNode(nodeIndex);
if(temp!=NULL) return temp;
}
if(this->pRChild!=NULL)
if(this->pRChild->index==nodeIndex)
return this->pRChild;
temp=this->pRChild->searchNode(nodeIndex);
return NULL;
舉報
樹,將為你開啟更精彩的數據結構大門,了解更多概念
1 回答關于Node::SearchNode方法是否應該修改成遞歸查找?
1 回答這是遞歸調用函數,請問它一直遞歸,會返還上一層嗎
1 回答關于遞歸調用,層次問題——筆記分享
1 回答我有一個問題,為什么Tree.h中的SearchNode()函數會調用Node.h中的SearchNode()函數,而不會調用自己類中的SearchNode()函數?這種情況在什么時候才可以發生?
1 回答AddNode()函數中增加節點 先在調用SearchNode()函數 的問題
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-03-16
后來改了,前面的是有錯,沒考慮周全
Node *Node::searchNode(int nodeIndex)
{
Node *temp=NULL;
if(this->index==nodeIndex) ?return this;
if(this->pLChild!=NULL)
{
if(this->pLChild->index==nodeIndex)
return this->pLChild;
else
{
temp=this->pLChild->searchNode(nodeIndex);
if(temp!=NULL) return temp;
}
}
if(this->pRChild!=NULL)
{
if(this->pRChild->index==nodeIndex)
return this->pRChild;
else
{
temp=this->pRChild->searchNode(nodeIndex);
if(temp!=NULL) return temp;
}
}
return NULL;
}