done remove()

This commit is contained in:
Sebastien Moll 2026-04-16 09:09:27 +02:00
parent a9165c3bfc
commit c3e188aab2

View file

@ -134,7 +134,13 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
@Override
public void remove(E x) throws ElementNotFoundException {
// TODO:
int index = this.array.indexOf(x);
if (index == -1 || index >= this.currentSize) { throw new ElementNotFoundException(x); }
E lastItem = this.array.get(--this.currentSize);
this.arraySet(index, lastItem);
this.percolateUp(index);
index = this.array.indexOf(lastItem);
this.percolateDown(index);
}
@Override