Ajout methode remove

This commit is contained in:
Auriane Lartigue 2020-03-27 17:14:01 +01:00
parent 0fcee12cd3
commit fe3a4d51e9

View file

@ -137,6 +137,24 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
@Override
public void remove(E x) throws ElementNotFoundException {
boolean trouve = false;
for (int i=0; i< this.currentSize; i++) {
if (this.array.get(i) == x) {
this.array.set(i,this.array.get(this.currentSize-1));
trouve = true;
}
}
if (!trouve) {
throw new ElementNotFoundException(x);
}
else {
this.currentSize--;
for(int i=0; i< this.currentSize ; i++) {
percolateDown(i);
}
}
// TODO:
}