Ajout methode remove
这个提交包含在:
父节点
0fcee12cd3
当前提交
fe3a4d51e9
共有 1 个文件被更改,包括 18 次插入 和 0 次删除
|
@ -137,6 +137,24 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
|||
|
||||
@Override
|
||||
public void remove(E x) throws ElementNotFoundException {
|
||||
boolean trouve = false;
|
||||
for (int i=0; i< this.currentSize; i++) {
|
||||
if (this.array.get(i) == x) {
|
||||
this.array.set(i,this.array.get(this.currentSize-1));
|
||||
trouve = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!trouve) {
|
||||
throw new ElementNotFoundException(x);
|
||||
}
|
||||
else {
|
||||
this.currentSize--;
|
||||
for(int i=0; i< this.currentSize ; i++) {
|
||||
percolateDown(i);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:
|
||||
}
|
||||
|
||||
|
|
正在加载…
在新工单中引用