This commit is contained in:
Bensouda Idriss 2023-04-04 16:16:37 +02:00
parent 912b726b4d
commit 25d2f1cf6f
2 changed files with 9 additions and 10 deletions

View file

@ -136,18 +136,17 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
}
@Override
// on est
// on est : tout faux utilise paircolletdown
public void remove(E x) throws ElementNotFoundException {
ArrayList<E> temp = new ArrayList<E>();
for (E e : array){
if (e != x){
temp.add(e);
}
int id = array.indexOf(x);
if (this.isEmpty() || this.size()==0 || id >= currentSize || id == -1){
throw new ElementNotFoundException(x);
}else {
this.array.set(array.indexOf(x), this.array.get(currentSize-1));
currentSize--;
percolateUp(id);
percolateDown(id);
}
for (int i=array.indexOf(x);i<array.size()-1;i++){
array.set(i, temp.get(i-1));
}
}
@Override