From: Jérôme Benoit Date: Sun, 4 Mar 2018 22:23:07 +0000 (+0100) Subject: TP2: Simplify the compacter method in the image class. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=38098a56346bfafe27f9be0fa1af916268105b8d;p=TP_POO.git TP2: Simplify the compacter method in the image class. Signed-off-by: Jérôme Benoit --- diff --git a/TP2/Image.java b/TP2/Image.java index 37bc6c3..8289930 100644 --- a/TP2/Image.java +++ b/TP2/Image.java @@ -67,9 +67,16 @@ class Image extends Forme implements Compactable { } public void compacter(int nElements) { - int minIndex = formeNumber - nElements - 1; + // Heavy solution + /* int minIndex = formeNumber - nElements - 1; for (int i = formeNumber - 1; (i > minIndex && !isEmpty()); i--) { supprimer(i); + } */ + // Lightweight solution + if (formeNumber - nElements > 0) { + formeNumber -= nElements; + } else { + formeNumber = 0; } }