wwxu
2016-08-03 20:58
如果删除的结点不是叶子结点,那该节点的子孙应该也需要置为0吧
bool SqBiTree::DeleteNode(int nodeIndex, int *pNode) { if (nodeIndex < 0 || nodeIndex > iSize - 1) { return false; } if (pBuffer[nodeIndex] == 0) { return false; } *pNode = pBuffer[nodeIndex]; pBuffer[nodeIndex] = 0; int lChildIndex = 2 * nodeIndex + 1; while (lChildIndex < iSize) { pBuffer[lChildIndex] = 0; lChildIndex = 2 * lChildIndex + 1; } int rChildIndex = 2 * nodeIndex + 2; while (rChildIndex < iSize) { pBuffer[rChildIndex] = 0; rChildIndex = 2 * rChildIndex + 2; } return true; }
数据结构探险之树篇
56461 学习 · 116 问题
相似问题