課程
/后端開發
/C++
/數據結構探險之樹篇
parent怎么加上去呢?
2016-08-31
源自:數據結構探險之樹篇 6-3
正在回答
對呀,講的是錯的,根本沒有考慮要插入的左右節點是否為空
這邊需要判斷左節點和右節點是否為空么?
//添加結點
bool Tree::AddNode(int nodeIndex,int direction,Node *pNode)
{
Node *temp=SearchNode(nodeIndex);
if(temp==NULL)
return false;
}
Node *node=new Node();
if(node==NULL)
{//申請內存失敗
node->index=pNode->index;
node->data=pNode->data;
node->pParent=temp;//注意這里?。。?!
if(direction==0)
{//插入到左邊
temp->pLChild=node;
if(direction==1)
{//插入到右邊
temp->pRChild=node;
return true;
京飛
七月戀堇 回復 京飛
舉報
樹,將為你開啟更精彩的數據結構大門,了解更多概念
3 回答關于james老師數據結構樹篇AddNode的一個BUG?
2 回答AddNode中檢測節點是否為空
1 回答為啥AddNode函數傳入的pNode需要是指針啊
1 回答AddNode()函數中增加節點 先在調用SearchNode()函數 的問題
1 回答關于pNode
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-11-06
對呀,講的是錯的,根本沒有考慮要插入的左右節點是否為空
2017-09-01
這邊需要判斷左節點和右節點是否為空么?
2016-09-04
//添加結點
bool Tree::AddNode(int nodeIndex,int direction,Node *pNode)
{
Node *temp=SearchNode(nodeIndex);
if(temp==NULL)
{
return false;
}
Node *node=new Node();
if(node==NULL)
{//申請內存失敗
return false;
}
node->index=pNode->index;
node->data=pNode->data;
node->pParent=temp;//注意這里?。。?!
if(direction==0)
{//插入到左邊
temp->pLChild=node;
}
if(direction==1)
{//插入到右邊
temp->pRChild=node;
}
return true;
}