---
title: "调整堆的算法"
author: "standalone"
date: "2010-09-25T10:34:35Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-09-25T10:34:35Z"
id: 770897
url: "https://standalone.iteye.com/blog/770897"
---

```
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
```