forked from menault/TD1_DEV51_Qualite_Algo
maj
This commit is contained in:
28
quicksort.c
Normal file
28
quicksort.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "quicksort.h"
|
||||
|
||||
int partition(int* array, int low, int high)
|
||||
{
|
||||
int pivot = array[high];
|
||||
int i = low -1;
|
||||
int j =low;
|
||||
for (j;j<high;j++){
|
||||
if (array[j]<= pivot){
|
||||
i=i+1;
|
||||
int a=array[j];
|
||||
array[j]=array[i];
|
||||
array[i]=a;
|
||||
}
|
||||
}
|
||||
int b = array[i+1];
|
||||
array[i+1]=array[high];
|
||||
array[high]=b;
|
||||
return i+1;
|
||||
}
|
||||
|
||||
void quicksort(int* array,int low, int high){
|
||||
if (low<high){
|
||||
int pi=partition(array,low,high);
|
||||
quicksort(array,low,pi-1);
|
||||
quicksort(array,pi+1,high);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user