Version Fonctionnelle : Ajout remove dans binary heap
This commit is contained in:
parent
241ff4901e
commit
e6be4aabac
1 changed files with 18 additions and 1 deletions
|
@ -137,7 +137,24 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
|||
|
||||
@Override
|
||||
public void remove(E x) throws ElementNotFoundException {
|
||||
// TODO:
|
||||
int index = 0;
|
||||
while (index<this.currentSize && !this.array.get(index).equals(x)) {
|
||||
index++;
|
||||
}
|
||||
if (index != this.currentSize) {
|
||||
E dernier = this.array.get(this.currentSize - 1);
|
||||
this.arraySet(index, dernier);
|
||||
this.arraySet(this.currentSize - 1, null);
|
||||
this.currentSize--;
|
||||
this.percolateDown(index);
|
||||
if (dernier.equals(this.array.get(index))) {
|
||||
this.percolateUp(index);
|
||||
}
|
||||
/*for (index = 0; index < this.currentSize; index++) {
|
||||
}*/
|
||||
} else {
|
||||
throw new ElementNotFoundException(x);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue