Skip to content

Commit

Permalink
added quick sort
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghiles1010 committed Mar 14, 2021
1 parent 8b3a949 commit cc5a08c
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ dkms.conf

# VSCode Files
.vscode/
Debug/
Release/
*.vcxproj*
x64/

#code blocks files
*.cbp
Expand All @@ -61,5 +65,6 @@ dkms.conf
bin/
obj/


# additional files
test_main.c
53 changes: 52 additions & 1 deletion algorithmes/quick_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,57 @@

#include "quick_sort.h"

long * quickSort(long * table, long taille){


// fonction qui permutte T[i] et T[j]
void swap(long* table, int i, int j) {

long temp;

temp = table[i];
table[i] = table[j];
table[j] = temp;
}

// Fonction qui met les fonctions inf au pivot ensemble
long partition(long* table, long low, long high) {

long i = low - 1, pivot = table[high], j;

for (j = low; j < high; j++) {

if (table[j] < pivot) {

i++;
swap(table, i, j);
}
}

swap(table, i + 1, high);

return i + 1;
}


//Fonction récursive
long* Sort(long* table, long low, long high) {

if (low < high) {

long pi = partition(table, low, high);

Sort(table, low, pi - 1);
Sort(table, pi + 1, high);

}

return table;
}




long* quickSort(long* table, long taille) {

return Sort(table, 0, taille-1);
}
4 changes: 2 additions & 2 deletions functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ int writeCSV(char * algorithm ,StoreTime * results, int taille){
char * file_name = malloc((15 + strlen(algorithm)) * sizeof(char));

sprintf(file_name, "results/%s.csv", algorithm);
fp=fopen(file_name,"w+");
fp= fopen(file_name,"w+");

if (fp == NULL){
printf("wellll");
printf("Fichier inexistant\n");
return 0;
}

Expand Down
25 changes: 22 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,32 @@
int main(){
srand(time(NULL));

int (* fonctions [1])(long*, long) = {heapSort};
char function_names[2][20] = { "Heap sort", "Quick sort" };

int (* fonctions [2])(long*, long) = {heapSort, quickSort};

long tab[6] = {10, 100};

StoreTime *results = tab_execution(fonctions[0], tab, 2);





for (int i = 0; i < 2; i++) {

printf("%s started.\n", function_names[i]);

StoreTime* results = tab_execution(fonctions[i], tab, 2);

writeCSV(function_names[i], results, 2);

printf("%s done.\n\n", function_names[i]);

}



writeCSV("heapSort", results, 2);


return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions results/Heap sort.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
num,time_ordered,time_inverse,time_random
10,0.0000000000,0.0000000000,0.0000000000
100,0.0000000000,0.0000000000,0.0000000000
3 changes: 3 additions & 0 deletions results/Quick sort.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
num,time_ordered,time_inverse,time_random
10,0.0000000000,0.0000000000,0.0000000000
100,0.0000000000,0.0000000000,0.0000000000

0 comments on commit cc5a08c

Please sign in to comment.