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
|
||||
// on est là
|
||||
// on est là : 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
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in a new issue