1 | import { Heap } from "./Heap";
|
2 |
|
3 | /**
|
4 | * 小顶堆
|
5 | */
|
6 | export class MinHeap<T> extends Heap<T>{
|
7 | constructor(private key?: keyof T){
|
8 | super();
|
9 | }
|
10 | protected compare(a: T, b: T): boolean {
|
11 | if (this.key){
|
12 | return a[this.key] <= b[this.key];
|
13 | }
|
14 | return a <= b;
|
15 | }
|
16 | }
|