From 7287cc551ef645485897f9fa58942b076f4af5e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 3 Mar 2017 18:28:43 +0100 Subject: [PATCH] Refinements to quick sort implementation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TP3/tp3.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TP3/tp3.c b/TP3/tp3.c index 4caf275..9198ad1 100644 --- a/TP3/tp3.c +++ b/TP3/tp3.c @@ -7,13 +7,14 @@ void AfficheTab(int T[], int n) { } } +/** This quick sort implementation only work with 2^n array size */ void TriFusion(int T[], int n) { int i = 0, j = 0, k = 0; int* T1; int* T2; T1 = malloc(n/2*sizeof(int)); - T2 = malloc((n - n/2)*sizeof(int)); + T2 = malloc(n/2*sizeof(int)); if (n > 1) { for (int i = 0; i < n/2; i++) { @@ -49,7 +50,7 @@ void TriFusion(int T[], int n) { } int main() { - int T[] = {4, 2, 7, 3, 8, 1, 6, 5}; + int T[] = {2, 7, 2, 3, 4, 1, 5, 5}; int tabSize = sizeof(T)/sizeof(T[0]); AfficheTab(T, tabSize); -- 2.34.1