From 569df90ab9f7e584fe5b8812320f8461c999647f Mon Sep 17 00:00:00 2001 From: Jerome Benoit Date: Sun, 5 Mar 2017 10:13:43 +0100 Subject: [PATCH] TP 2 exo3: randomly choose the pivot in quick sort Signed-off-by: Jerome Benoit --- TP2/exo3/exo3.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TP2/exo3/exo3.c b/TP2/exo3/exo3.c index f070f1f..29ebcb0 100644 --- a/TP2/exo3/exo3.c +++ b/TP2/exo3/exo3.c @@ -1,4 +1,5 @@ #include +#include void permuter(int T[], int i1, int i2) { int tmp = T[i1]; @@ -14,7 +15,8 @@ void AfficheTab(int T[], int n) { void TriRapide(int T[], int n) { // The optimal pivot choice is the median value in the tab - int pivot = T[0]; + int index_pivot = arc4random_uniform(n); + int pivot = T[index_pivot]; int TP[n]; int TG[n]; int np = 0; -- 2.34.1