wip(binheap): remove
This commit is contained in:
parent
e45e83dc69
commit
04c4316e36
1 changed files with 8 additions and 9 deletions
|
@ -137,17 +137,16 @@ 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:
|
// TODO optimize indexOf
|
||||||
if (isEmpty() || !array.contains(x)) {
|
int index = array.indexOf(x);
|
||||||
|
if (isEmpty() || index == -1 || index >= this.currentSize) {
|
||||||
throw new ElementNotFoundException(x);
|
throw new ElementNotFoundException(x);
|
||||||
}
|
}
|
||||||
int indice_suppression = array.indexOf(x);
|
|
||||||
arraySet(indice_suppression, array.get(this.currentSize - 1));
|
// replace element with last element
|
||||||
//array.remove(this.currentSize);
|
arraySet(index, array.get(--this.currentSize));
|
||||||
this.currentSize--;
|
|
||||||
if (indice_suppression < this.currentSize) {
|
percolateDown(index);
|
||||||
percolateDown(indice_suppression);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue