From c68a969b918330720af09c3daf1ce0abcffb33c1 Mon Sep 17 00:00:00 2001 From: Clement LACAU Date: Fri, 5 Apr 2024 00:55:52 +0200 Subject: [PATCH] Edge cases to fix --- .../org/insa/graphs/algorithm/utils/BinaryHeap.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 6ef1438..cd77e5c 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 @@ -141,13 +141,13 @@ public class BinaryHeap> implements PriorityQueue { if (isEmpty() || !array.contains(x)) { throw new ElementNotFoundException(x); } - int pere = 1; int indice_suppression = array.indexOf(x); - array.remove(indice_suppression); - arraySet(indice_suppression, array.get(this.currentSize)); - array.remove(this.currentSize); - percolateUp(indice_suppression); + arraySet(indice_suppression, array.get(this.currentSize - 1)); + //array.remove(this.currentSize); this.currentSize--; + if (indice_suppression < this.currentSize) { + percolateDown(indice_suppression); + } } @Override