From: Jérôme Benoit Date: Fri, 3 Mar 2017 17:28:43 +0000 (+0100) Subject: Refinements to quick sort implementation X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7287cc551ef645485897f9fa58942b076f4af5e4;p=Algorithmic_C.git Refinements to quick sort implementation Signed-off-by: Jérôme Benoit --- 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);