Skip to content

Commit cc0a6d9

Browse files
committed
Fix
1 parent 8ffab66 commit cc0a6d9

File tree

1 file changed

+3
-3
lines changed
  • src/main/java/com/thealgorithms/datastructures/heaps

1 file changed

+3
-3
lines changed

src/main/java/com/thealgorithms/datastructures/heaps/MinHeap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private HeapElement extractMin() throws EmptyHeapException {
197197
if (minHeap.isEmpty()) {
198198
throw new EmptyHeapException("Cannot extract from empty heap");
199199
}
200-
HeapElement result = minHeap.get(0);
200+
HeapElement result = minHeap.getFirst();
201201
deleteElement(1);
202202
return result;
203203
}
@@ -227,8 +227,8 @@ public void deleteElement(int elementIndex) throws EmptyHeapException {
227227
}
228228

229229
// Replace with last element and remove last position
230-
minHeap.set(elementIndex - 1, minHeap.get(minHeap.size() - 1));
231-
minHeap.remove(minHeap.size() - 1);
230+
minHeap.set(elementIndex - 1, minHeap.getLast());
231+
minHeap.removeLast();
232232

233233
// No need to toggle if we just removed the last element
234234
if (!minHeap.isEmpty() && elementIndex <= minHeap.size()) {

0 commit comments

Comments
 (0)