Skip to content

Commit dc9c6a4

Browse files
committed
Update README.md with quick sort details
1 parent 27be722 commit dc9c6a4

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

README.md

+55-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ void print_array(const int *array, size_t size)
6363
printf("\n");
6464
}
6565
```
66-
6766
```
6867
#include <stdio.h>
6968
#include "sort.h"
@@ -136,7 +135,7 @@ Write a function that sorts an array of integers in ascending order using the [B
136135
* Prototype: `void bubble_sort(int *array, size_t size);`
137136
* You’re expected to print the array after each time you swap two elements (See example below)
138137

139-
* Write in the file `0-O`, the big O notations of the time complexity of the `Bubble sort` algorithm, with `1` notation per line:
138+
Write in the file `0-O`, the big O notations of the time complexity of the `Bubble sort` algorithm, with `1` notation per line:
140139

141140
* in the best case
142141
* in the average case
@@ -349,3 +348,57 @@ alex@/tmp/sort$ ./select
349348
7, 13, 19, 48, 52, 71, 73, 86, 96, 99
350349
alex@/tmp/sort$
351350
```
351+
352+
[3. Quick sort](./3-quick_sort.c)
353+
354+
Write a function that sorts an array of integers in ascending order using the [Quick sort](https://en.wikipedia.org/wiki/Quicksort) algorithm
355+
356+
* Prototype: `void quick_sort(int *array, size_t size);`
357+
* You must implement the `Lomuto` partition scheme.
358+
* The pivot should always be the last element of the partition being sorted.
359+
* You’re expected to print the `array` after each time you swap two elements (See example below)
360+
361+
Write in the file `3-O`, the big O notations of the time complexity of the `Quick sort` algorithm, with `1` notation per line:
362+
363+
* in the best case
364+
* in the average case
365+
* in the worst case
366+
367+
```
368+
alex@/tmp/sort$ cat 3-main.c
369+
#include <stdio.h>
370+
#include <stdlib.h>
371+
#include "sort.h"
372+
373+
/**
374+
* main - Entry point
375+
*
376+
* Return: Always 0
377+
*/
378+
int main(void)
379+
{
380+
int array[] = {19, 48, 99, 71, 13, 52, 96, 73, 86, 7};
381+
size_t n = sizeof(array) / sizeof(array[0]);
382+
383+
print_array(array, n);
384+
printf("\n");
385+
quick_sort(array, n);
386+
printf("\n");
387+
print_array(array, n);
388+
return (0);
389+
}
390+
alex@/tmp/sort$ gcc -Wall -Wextra -Werror -pedantic -std=gnu89 3-main.c 3-quick_sort.c print_array.c -o quick
391+
alex@/tmp/sort$ ./quick
392+
19, 48, 99, 71, 13, 52, 96, 73, 86, 7
393+
394+
7, 48, 99, 71, 13, 52, 96, 73, 86, 19
395+
7, 13, 99, 71, 48, 52, 96, 73, 86, 19
396+
7, 13, 19, 71, 48, 52, 96, 73, 86, 99
397+
7, 13, 19, 71, 48, 52, 73, 96, 86, 99
398+
7, 13, 19, 71, 48, 52, 73, 86, 96, 99
399+
7, 13, 19, 48, 71, 52, 73, 86, 96, 99
400+
7, 13, 19, 48, 52, 71, 73, 86, 96, 99
401+
402+
7, 13, 19, 48, 52, 71, 73, 86, 96, 99
403+
alex@/tmp/sort$
404+
```

0 commit comments

Comments
 (0)