二叉树的数组实现
如果删除的结点不是叶子结点,那该节点的子孙应该也需要置为0吧
如果删除的结点不是叶子结点,那该节点的子孙应该也需要置为0吧
2016-08-03
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;
}举报