Pop 移除并返回最小元素
()
| 58 | |
| 59 | // Pop 移除并返回最小元素 |
| 60 | func (pq *PriorityQueue[T]) Pop() interface{} { |
| 61 | if len(pq.items) == 0 { |
| 62 | return nil |
| 63 | } |
| 64 | old := pq.items |
| 65 | n := len(old) |
| 66 | item := old[n-1] |
| 67 | pq.items = old[0 : n-1] |
| 68 | return item |
| 69 | } |
| 70 | |
| 71 | // Enqueue 添加一个元素 |
| 72 | func (pq *PriorityQueue[T]) Enqueue(item T) error { |