added heap management

This commit is contained in:
Lacroix Raphael 2022-03-28 09:53:05 +02:00
parent 7d134df36b
commit a50762edbe

View file

@ -137,7 +137,15 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
@Override @Override
public void remove(E x) throws ElementNotFoundException { public void remove(E x) throws ElementNotFoundException {
// TODO: // index of is not optimized but it's better than nothing. We will come back to improve it if we have time at the end
int i = this.array.indexOf(x);
if (i == -1 || i > this.currentSize - 1) {
throw new ElementNotFoundException(x);
}
E lastItem = this.array.get(--this.currentSize);
this.arraySet(i, lastItem);
this.percolateDown(i);
this.percolateUp(i);
} }
@Override @Override