RemoveTerminé
This commit is contained in:
parent
92481f4b6a
commit
38cc94bf65
1 changed files with 26 additions and 1 deletions
|
@ -134,7 +134,32 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
|||
|
||||
@Override
|
||||
public void remove(E x) throws ElementNotFoundException {
|
||||
// TODO:
|
||||
|
||||
int xIndex = this.array.indexOf(x);
|
||||
if(xIndex < 0 || xIndex > this.currentSize-1){
|
||||
|
||||
throw new ElementNotFoundException(x);
|
||||
}
|
||||
|
||||
|
||||
else{
|
||||
|
||||
E last = this.array.get(this.currentSize-1);
|
||||
|
||||
this.arraySet(xIndex, last);
|
||||
this.currentSize--;
|
||||
|
||||
int PIndex = indexParent(xIndex);
|
||||
|
||||
E Parent = this.array.get(PIndex);
|
||||
|
||||
|
||||
|
||||
this.percolateUp(xIndex); // les comparaisons sont déjà gérées dans les percolates et sont récursif
|
||||
this.percolateDown(xIndex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue