Skip to content

Commit 6322305

Browse files
committed
Merge branch 'develop'
2 parents 60a5585 + 02de4ed commit 6322305

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

DataStructure/Java/_09_Heap/Heap.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ public E remove() {
166166
throw new NoSuchElementException();
167167
}
168168
E result = (E) array[1];
169-
E target = (E) array[size];
169+
E target;
170+
if(size == 1) {
171+
target = null;
172+
}
173+
else {
174+
target = (E) array[size];
175+
}
170176
array[size] = null;
171177
size--;
172178
siftDown(1, target);

DataStructure/Java/_10_PriorityQueue/PriorityQueue.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,13 @@ public E remove() {
194194
}
195195

196196
E result = (E) array[1];
197-
E target = (E) array[size];
197+
E target;
198+
if(size == 1) {
199+
target = null;
200+
}
201+
else {
202+
target = (E) array[size];
203+
}
198204

199205
array[size] = null;
200206
size--;

0 commit comments

Comments
 (0)