From 38098a56346bfafe27f9be0fa1af916268105b8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 4 Mar 2018 23:23:07 +0100 Subject: [PATCH] TP2: Simplify the compacter method in the image class. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TP2/Image.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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; } } -- 2.34.1