|
@@ -138,10 +138,10 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
138
|
138
|
@Override
|
139
|
139
|
public void remove(E x) throws ElementNotFoundException {
|
140
|
140
|
int index=this.array.indexOf(x);
|
141
|
|
- if (index<0)
|
|
141
|
+ if (index<0 || this.currentSize<=index)
|
142
|
142
|
throw new ElementNotFoundException(x);
|
143
|
143
|
|
144
|
|
- this.array.set(index, this.array.get(this.array.size()-1));
|
|
144
|
+ this.array.set(index, this.array.get(this.currentSize-1));
|
145
|
145
|
this.currentSize--;
|
146
|
146
|
this.percolateDown(index);
|
147
|
147
|
}
|