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 @Override
// on est // on est : tout faux utilise paircolletdown
public void remove(E x) throws ElementNotFoundException { public void remove(E x) throws ElementNotFoundException {
ArrayList<E> temp = new ArrayList<E>(); int id = array.indexOf(x);
for (E e : array){ if (this.isEmpty() || this.size()==0 || id >= currentSize || id == -1){
if (e != x){ throw new ElementNotFoundException(x);
temp.add(e); }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 @Override