Compare commits

..

2 commits

Author SHA1 Message Date
c68a969b91 Edge cases to fix 2024-04-05 00:55:52 +02:00
2e20b9b3a6 heap removed impl, tests to fix 2024-04-05 00:37:26 +02:00

View file

@ -138,6 +138,16 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
@Override @Override
public void remove(E x) throws ElementNotFoundException { public void remove(E x) throws ElementNotFoundException {
// TODO: // TODO:
if (isEmpty() || !array.contains(x)) {
throw new ElementNotFoundException(x);
}
int indice_suppression = array.indexOf(x);
arraySet(indice_suppression, array.get(this.currentSize - 1));
//array.remove(this.currentSize);
this.currentSize--;
if (indice_suppression < this.currentSize) {
percolateDown(indice_suppression);
}
} }
@Override @Override