added heap management
This commit is contained in:
parent
7d134df36b
commit
a50762edbe
1 changed files with 9 additions and 1 deletions
|
@ -137,7 +137,15 @@ 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:
|
// index of is not optimized but it's better than nothing. We will come back to improve it if we have time at the end
|
||||||
|
int i = this.array.indexOf(x);
|
||||||
|
if (i == -1 || i > this.currentSize - 1) {
|
||||||
|
throw new ElementNotFoundException(x);
|
||||||
|
}
|
||||||
|
E lastItem = this.array.get(--this.currentSize);
|
||||||
|
this.arraySet(i, lastItem);
|
||||||
|
this.percolateDown(i);
|
||||||
|
this.percolateUp(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue