Edge cases to fix

This commit is contained in:
Clement Lacau 2024-04-05 00:55:52 +02:00
parent 2e20b9b3a6
commit c68a969b91

View file

@ -141,13 +141,13 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
if (isEmpty() || !array.contains(x)) { if (isEmpty() || !array.contains(x)) {
throw new ElementNotFoundException(x); throw new ElementNotFoundException(x);
} }
int pere = 1;
int indice_suppression = array.indexOf(x); int indice_suppression = array.indexOf(x);
array.remove(indice_suppression); arraySet(indice_suppression, array.get(this.currentSize - 1));
arraySet(indice_suppression, array.get(this.currentSize)); //array.remove(this.currentSize);
array.remove(this.currentSize);
percolateUp(indice_suppression);
this.currentSize--; this.currentSize--;
if (indice_suppression < this.currentSize) {
percolateDown(indice_suppression);
}
} }
@Override @Override