remove
This commit is contained in:
parent
912b726b4d
commit
25d2f1cf6f
2 changed files with 9 additions and 10 deletions
|
|
@ -136,18 +136,17 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
// on est là
|
// on est là : 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
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in a new issue