ITeye博客

调整堆的算法

standalone · 2010-09-25 10:34 · c++ · 编程语言 · Markdown

Begin
adjustHeap(A[], i) // Heapify takes in our heap and index of current root node of subtree to be heapified
{
left=leftChild();
right=rightChild();
largest=i;
if left<=A.heap-size AND A[left]>A[i] {
largest=left;
}
if right<=A.heap-size AND A[right]>A[i] {
largest=right;
}

if largest NOT EQUAL i {
swap A[i] and A[largest]
adjustHeap[A, largest)
}
END

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。