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 {
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 ()) {
You can’t perform that action at this time.
0 commit comments