forked from lebotlan/BE-Graphes
done remove()
This commit is contained in:
parent
a9165c3bfc
commit
c3e188aab2
1 changed files with 7 additions and 1 deletions
|
|
@ -134,7 +134,13 @@ 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 {
|
||||||
// TODO:
|
int index = this.array.indexOf(x);
|
||||||
|
if (index == -1 || index >= this.currentSize) { throw new ElementNotFoundException(x); }
|
||||||
|
E lastItem = this.array.get(--this.currentSize);
|
||||||
|
this.arraySet(index, lastItem);
|
||||||
|
this.percolateUp(index);
|
||||||
|
index = this.array.indexOf(lastItem);
|
||||||
|
this.percolateDown(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue