From 668a5cdf6a9ac1a37ba7070befb10d95233d1c78 Mon Sep 17 00:00:00 2001 From: Aditya Raj Sinha Date: Tue, 11 Oct 2022 19:17:26 +0530 Subject: [PATCH] Added Quick sort Algorithm issue #9 --- Sorting Algorithms/quicksort.py | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Sorting Algorithms/quicksort.py diff --git a/Sorting Algorithms/quicksort.py b/Sorting Algorithms/quicksort.py new file mode 100644 index 0000000..25d68b4 --- /dev/null +++ b/Sorting Algorithms/quicksort.py @@ -0,0 +1,58 @@ +''' + + Online Python Compiler. + Code, Compile, Run and Debug python program online. +Write your code in this editor and press "Run" button to execute it. + +''' + +def partition(array, low, high): + + + pivot = array[high] + + + i = low - 1 + + + for j in range(low, high): + if array[j] <= pivot: + + + i = i + 1 + + + (array[i], array[j]) = (array[j], array[i]) + + + (array[i + 1], array[high]) = (array[high], array[i + 1]) + + + return i + 1 + + + + +def quickSort(array, low, high): + if low < high: + + pi = partition(array, low, high) + + + quickSort(array, low, pi - 1) + + + quickSort(array, pi + 1, high) + + +data = [74,205,-19,32,-94,23,378,878,297,296,795,774,771] +print("Initial Array") +print(data) + +size = len(data) + +quickSort(data, 0, size - 1) + +print('Resultant Array:') +print(data) +