feat(binheap): remove passes tests
This commit is contained in:
parent
04c4316e36
commit
cce3fcdca8
1 changed files with 5 additions and 4 deletions
|
@ -137,16 +137,17 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
|||
|
||||
@Override
|
||||
public void remove(E x) throws ElementNotFoundException {
|
||||
// TODO optimize indexOf
|
||||
int index = array.indexOf(x);
|
||||
if (isEmpty() || index == -1 || index >= this.currentSize) {
|
||||
throw new ElementNotFoundException(x);
|
||||
}
|
||||
|
||||
// replace element with last element
|
||||
arraySet(index, array.get(--this.currentSize));
|
||||
// replace element with the min
|
||||
arraySet(index, this.findMin());
|
||||
|
||||
percolateDown(index);
|
||||
percolateUp(index);
|
||||
|
||||
this.deleteMin();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue