RemoveTerminé

This commit is contained in:
Gasson-Betuing Danyl 2025-04-29 18:31:01 +02:00
parent 92481f4b6a
commit 38cc94bf65

View file

@ -134,7 +134,32 @@ 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:
int xIndex = this.array.indexOf(x);
if(xIndex < 0 || xIndex > this.currentSize-1){
throw new ElementNotFoundException(x);
}
else{
E last = this.array.get(this.currentSize-1);
this.arraySet(xIndex, last);
this.currentSize--;
int PIndex = indexParent(xIndex);
E Parent = this.array.get(PIndex);
this.percolateUp(xIndex); // les comparaisons sont déjà gérées dans les percolates et sont récursif
this.percolateDown(xIndex);
}
} }
@Override @Override