From fe3a4d51e9ed9283f85fe85c7cdd16fda8d4727d Mon Sep 17 00:00:00 2001 From: alartigu Date: Fri, 27 Mar 2020 17:14:01 +0100 Subject: [PATCH] Ajout methode remove --- .../graphs/algorithm/utils/BinaryHeap.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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..c3ee13a 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,6 +137,24 @@ public class BinaryHeap> implements PriorityQueue { @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: }