8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 23f1610 commit d0a9d74Copy full SHA for d0a9d74
src/data_structure/heap/MinHeap.java
@@ -88,6 +88,24 @@ public boolean remove(Object o) {
88
}
89
90
91
+ /**
92
+ * 移除最小堆的首节点
93
+ *
94
+ * @return 首节点元素
95
+ */
96
+ public E poll() {
97
+ int s = data.size();
98
+ if (s == 0) {
99
+ return null;
100
+ }
101
+
102
+ E result = data.get(0);
103
+ E x = data.remove(s - 1);
104
+ siftDown(0, x);
105
106
+ return result;
107
108
109
/*=============================================================*/
110
/*========================== 私有方法 ==========================*/
111
0 commit comments