File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
src/main/java/com/thealgorithms/datastructures/heaps Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -197,7 +197,7 @@ private HeapElement extractMin() throws EmptyHeapException {
197
197
if (minHeap .isEmpty ()) {
198
198
throw new EmptyHeapException ("Cannot extract from empty heap" );
199
199
}
200
- HeapElement result = minHeap .get ( 0 );
200
+ HeapElement result = minHeap .getFirst ( );
201
201
deleteElement (1 );
202
202
return result ;
203
203
}
@@ -227,8 +227,8 @@ public void deleteElement(int elementIndex) throws EmptyHeapException {
227
227
}
228
228
229
229
// 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 ( );
232
232
233
233
// No need to toggle if we just removed the last element
234
234
if (!minHeap .isEmpty () && elementIndex <= minHeap .size ()) {
You can’t perform that action at this time.
0 commit comments