tas binaire remove

This commit is contained in:
Pellerin Tiphaine 2026-04-16 09:10:36 +02:00
parent 5d682d1872
commit 8ce411fcd2

View file

@ -135,6 +135,22 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
@Override
public void remove(E x) throws ElementNotFoundException {
// TODO:
if (this.isEmpty()) {
throw new ElementNotFoundException(x);
}
int i = this.array.indexOf(x);
if (i == -1) {
throw new ElementNotFoundException(x);
}
if (i > this.size() - 1) {
throw new ElementNotFoundException(x);
}
else {
this.arraySet(i, this.array.get(this.size() - 1));
this.percolateUp(i);
this.percolateDown(i);
this.currentSize -= 1;
}
}
@Override