LZ正在看数据结构与算法分析C语言版 有个问题想请教大家
在其中的优先队列中 讲到关于二项队列的一些问题 其中的有段代码不理解,还请大家赐教,关于删除最小值的代码如下
ElementType DeleteMin(BinQueue H)
{
int i,j;
int MinTree;
BinQueue DeleteQueue;
Position DeletedTree, OldRoot;
ElementType MinItem;
if(IsEmpty(H))
{
Error("Empty BinQueue!!");
return -Infinity;
}
//find the minmum
Min = Infinity;
for(i=0;i<MaxTree;i++)
{
if(H->TheTrees[i] && H->TheTrees[i]->Element<MinItem)
{
// Updata the minmun
MiniItem = H->TheTrees[i]->Element;
MinTree = i;
}
}
// have found the DeleteTree
DeleteTree = H->TheTrees[MinTree];
OldRoot = DeleteTree;
DeleteTree = OldRoot->LeftChild;
free(OldRoot);
// form the DeleteQueue
DeletedQueue = Initialize();
DeletedQueue->CurrentSize = (1<<MinTree) - 1;
for(j=MinTree-1;j>=0;j--)
{
DeletedQueue->TheTree[j] = DeletedTree;
DeletedTree = DeletedTree->Sibling;
DeletedQueue->TheTree[j]->Sibling = NULL;
}
H->TheTrees[MiniTree] = NULL;
H->CurrentSize -= DeletedQueue->CurrentSize+1;
Merge(H,DeletedQueue);
return MinItem;
}
其中倒数第三行代码不甚理解 请大家赐教