From 70760a4e70565da4762dce0579e7ebc002ca2c18 Mon Sep 17 00:00:00 2001 From: KSenior2608 <56647443+KSenior2608@users.noreply.github.com> Date: Thu, 17 Oct 2019 20:24:02 +0530 Subject: [PATCH] Create quick_sort_on_doubly_linked_list.cpp --- .../quick_sort_on_doubly_linked_list.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 KSenior2608/quick_sort_on_doubly_linked_list.cpp diff --git a/KSenior2608/quick_sort_on_doubly_linked_list.cpp b/KSenior2608/quick_sort_on_doubly_linked_list.cpp new file mode 100644 index 0000000..4331f07 --- /dev/null +++ b/KSenior2608/quick_sort_on_doubly_linked_list.cpp @@ -0,0 +1,28 @@ + +int partition (int arr[], int l, int h) +{ + int x = arr[h]; + int i = (l - 1); + + for (int j = l; j <= h- 1; j++) + { + if (arr[j] <= x) + { + i++; + swap (&arr[i], &arr[j]); + } + } + swap (&arr[i + 1], &arr[h]); + return (i + 1); +} + + +void quickSort(int A[], int l, int h) +{ + if (l < h) + { + int p = partition(A, l, h); /* Partitioning index */ + quickSort(A, l, p - 1); + quickSort(A, p + 1, h); + } +}