From 48139d1c1d8f4da22a4ea474abe6f1f6aeffcaad Mon Sep 17 00:00:00 2001 From: mithe24 Date: Wed, 29 Oct 2025 15:25:13 +0100 Subject: report(qsort): add part about qsort --- report/qsort.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 report/qsort.c (limited to 'report/qsort.c') diff --git a/report/qsort.c b/report/qsort.c new file mode 100644 index 0000000..6877369 --- /dev/null +++ b/report/qsort.c @@ -0,0 +1,21 @@ +void quicksort(int arr[], int lo, int hi) { + if (lo >= 0 && hi >= 0 && lo < hi) { + int p = partition(A, lo, hi) + quicksort(A, lo, p) + quicksort(A, p + 1, hi) + } +} + +int partition(int arr[], int lo, int hi) { + int pivot = arr[lo]; + int i = lo - 1, j = hi + 1; + while (true) { + do { i++; } while (arr[i] < pivot); + do { j--; } while (arr[j] > pivot); + if (i >= j) break; + int temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + return j; +} -- cgit v1.2.3-70-g09d2