diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeap.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeap.java index 2c1a239..7a17c6b 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeap.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeap.java @@ -137,7 +137,15 @@ public class BinaryHeap> implements PriorityQueue { @Override public void remove(E x) throws ElementNotFoundException { - // TODO: + // index of is not optimized but it's better than nothing. We will come back to improve it if we have time at the end + int i = this.array.indexOf(x); + if (i == -1 || i > this.currentSize - 1) { + throw new ElementNotFoundException(x); + } + E lastItem = this.array.get(--this.currentSize); + this.arraySet(i, lastItem); + this.percolateDown(i); + this.percolateUp(i); } @Override