tas binaire remove
This commit is contained in:
parent
5d682d1872
commit
8ce411fcd2
1 changed files with 16 additions and 0 deletions
|
|
@ -135,6 +135,22 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
|||
@Override
|
||||
public void remove(E x) throws ElementNotFoundException {
|
||||
// TODO:
|
||||
if (this.isEmpty()) {
|
||||
throw new ElementNotFoundException(x);
|
||||
}
|
||||
int i = this.array.indexOf(x);
|
||||
if (i == -1) {
|
||||
throw new ElementNotFoundException(x);
|
||||
}
|
||||
if (i > this.size() - 1) {
|
||||
throw new ElementNotFoundException(x);
|
||||
}
|
||||
else {
|
||||
this.arraySet(i, this.array.get(this.size() - 1));
|
||||
this.percolateUp(i);
|
||||
this.percolateDown(i);
|
||||
this.currentSize -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in a new issue