Version Fonctionnelle : Ajout remove dans binary heap

This commit is contained in:
Paul Faure 2020-03-27 17:04:41 +01:00
parent 241ff4901e
commit e6be4aabac

View file

@ -137,7 +137,24 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
@Override
public void remove(E x) throws ElementNotFoundException {
// TODO:
int index = 0;
while (index<this.currentSize && !this.array.get(index).equals(x)) {
index++;
}
if (index != this.currentSize) {
E dernier = this.array.get(this.currentSize - 1);
this.arraySet(index, dernier);
this.arraySet(this.currentSize - 1, null);
this.currentSize--;
this.percolateDown(index);
if (dernier.equals(this.array.get(index))) {
this.percolateUp(index);
}
/*for (index = 0; index < this.currentSize; index++) {
}*/
} else {
throw new ElementNotFoundException(x);
}
}
@Override