()
| 68 | } |
| 69 | |
| 70 | extractMin(): T | undefined { |
| 71 | if (this.heap.length === 0) return undefined |
| 72 | |
| 73 | const minItem = this.heap[0].item |
| 74 | const last = this.heap.pop()! |
| 75 | |
| 76 | if (this.heap.length > 0) { |
| 77 | this.heap[0] = last |
| 78 | this.siftDown(0) |
| 79 | } |
| 80 | |
| 81 | return minItem |
| 82 | } |
| 83 | |
| 84 | get size(): number { |
| 85 | return this.heap.length |