Ajout methode remove
This commit is contained in:
parent
0fcee12cd3
commit
fe3a4d51e9
1 changed files with 18 additions and 0 deletions
|
@ -137,6 +137,24 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(E x) throws ElementNotFoundException {
|
public void remove(E x) throws ElementNotFoundException {
|
||||||
|
boolean trouve = false;
|
||||||
|
for (int i=0; i< this.currentSize; i++) {
|
||||||
|
if (this.array.get(i) == x) {
|
||||||
|
this.array.set(i,this.array.get(this.currentSize-1));
|
||||||
|
trouve = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!trouve) {
|
||||||
|
throw new ElementNotFoundException(x);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.currentSize--;
|
||||||
|
for(int i=0; i< this.currentSize ; i++) {
|
||||||
|
percolateDown(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue