package heap;
import java.util.ArrayList;
import java.util.List;
/**
* 二叉堆(最小堆)
* Created by long.chen on 2017/12/25.
*/
public class BinaryHeapMin<T extends Comparable<T>> {
private List<T> heap;
public BinaryHeapMin() {
this.heap = new ArrayList<>();
}
/**
* 向下调整
*
* @param start
* @param end
*/
public void fliterdown(int start, int end) {
int left = 2 * start + 1;
T temp = heap.get(start);
while (left <= end) {
int tempSec = heap.get(left).compareTo(heap.get(left + 1));
if (left < end && tempSec > 0)
left++;
tempSec = temp.compareTo(heap.get(left));
if (tempSec <= 0)
break;
else {
heap.set(start, heap.get(left));
start = left;
lef
BinaryHeap (最小堆)
最新推荐文章于 2022-06-09 10:38:42 发布