@@ -63,7 +63,6 @@ void print_array(const int *array, size_t size)
63
63
printf("\n");
64
64
}
65
65
```
66
-
67
66
```
68
67
#include <stdio.h>
69
68
#include "sort.h"
@@ -136,7 +135,7 @@ Write a function that sorts an array of integers in ascending order using the [B
136
135
* Prototype: `void bubble_sort(int *array, size_t size);`
137
136
* You’re expected to print the array after each time you swap two elements (See example below)
138
137
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:
140
139
141
140
* in the best case
142
141
* in the average case
@@ -349,3 +348,57 @@ alex@/tmp/sort$ ./select
349
348
7, 13, 19, 48, 52, 71, 73, 86, 96, 99
350
349
alex@/tmp/sort$
351
350
```
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