Skip to content

Commit

Permalink
复习堆
Browse files Browse the repository at this point in the history
  • Loading branch information
Xikl committed Oct 8, 2019
1 parent 8642397 commit b98392c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/ximo/datastructuresinaction/heap/MaxHeap.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import com.ximo.datastructuresinaction.array.Array;

/**
* 二叉堆的定义:
* 1.是一颗完全二叉树
* 2.大顶堆的父节点元素要比其左右孩子节点要大(小顶堆反之)
*
* 大顶堆
* 当数组索引从1开,那么
* parent = i / 2
Expand Down Expand Up @@ -30,10 +34,12 @@ public MaxHeap() {
}

/**
* 找到最后一个叶子节点,然后找到他的父亲节点
*
*
* heapify:
* 将任意数组变成一个堆
* 1.主要思想是找到最后一个非叶子节点索引k(最后一个节点的父节点)
* 2.然后进行下沉操作siftDown(k)
*
* 找到最后一个叶子节点,然后找到他的父亲节点
* @param arr
*/
public MaxHeap(E[] arr) {
Expand Down

0 comments on commit b98392c

Please sign in to comment.