This commit is contained in:
2025-09-10 17:21:59 +02:00
parent ca552281c9
commit 83c915801c
7 changed files with 237 additions and 4 deletions

28
quicksort.c Normal file
View 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);
}
}