From 9bd6197002ea6286b8542d185dda98dc3a330cbe Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 14 Feb 2017 22:50:42 +0100 Subject: [PATCH] sortFirst(): only change the return value once, not at every iteration when a permutation is done. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- exo1/exo1.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exo1/exo1.c b/exo1/exo1.c index 8b44ea4..b4bf35d 100644 --- a/exo1/exo1.c +++ b/exo1/exo1.c @@ -32,11 +32,13 @@ void displayArray(int* array, int count) { bool sortFirst(int* array, int length) { bool rt = false; + // This loop could probably be replaced by a while loop with conditions + // on the array values permutation AND the iteration value, later ... for (int i = 0; i < length-1; i++) { if (array[i] > array[i+1]) { swap(&array[i], &array[i+1]); //xorSwap(&array[i], &array[i+1]); - rt = true; + if (!rt) { rt = true; }; } } return rt; -- 2.34.1