* @zh 弹出最小元素 * @en Pop minimum element
()
| 49 | * @en Pop minimum element |
| 50 | */ |
| 51 | pop(): T | undefined { |
| 52 | if (this.heap.length === 0) { |
| 53 | return undefined; |
| 54 | } |
| 55 | |
| 56 | const result = this.heap[0]; |
| 57 | const last = this.heap.pop()!; |
| 58 | |
| 59 | if (this.heap.length > 0) { |
| 60 | this.heap[0] = last; |
| 61 | this.sinkDown(0); |
| 62 | } |
| 63 | |
| 64 | return result; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @zh 查看最小元素(不移除) |