8000 feat(min heap): Add method of getting the first element · HuboArch/algorithms-in-java@60a60fd · GitHub
[go: up one dir, main page]

Skip to content

Commit 60a60fd

Browse files
author
agribeau
committed
feat(min heap): Add method of getting the first element
1 parent d0a9d74 commit 60a60fd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/data_structure/heap/MinHeap.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ public E poll() {
106106
return result;
107107
}
108108

109+
/**
110+
* 获取最小堆首元素
111+
*
112+
* @return 首元素
113+
*/
114+
public E peek() {
115+
return data.isEmpty() ? null : data.get(0);
116+
}
117+
109118
/*=============================================================*/
110119
/*========================== 私有方法 ==========================*/
111120
/*=============================================================*/

0 commit comments

Comments
 (0)
0