1 | import { Heap } from "./Heap";
|
2 |
|
3 | /**
|
4 | * 大顶堆
|
5 | */
|
6 | export class MaxHeap<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 | }
|