From 22a8553f11c3cb527ac054fb422f8284baa48db3 Mon Sep 17 00:00:00 2001 From: UN997 Date: Thu, 4 Oct 2018 01:27:13 +0530 Subject: [PATCH] Added quick sort --- sorting/quick_sort.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sorting/quick_sort.py diff --git a/sorting/quick_sort.py b/sorting/quick_sort.py new file mode 100644 index 0000000..0ad549c --- /dev/null +++ b/sorting/quick_sort.py @@ -0,0 +1,42 @@ + +def quickSort(alist): + + quickSortHelper(alist,0,len(alist)-1) + +def quickSortHelper(alist,first,last): + + if first= pivotvalue and rightmark >= leftmark: + rightmark = rightmark -1 + + if rightmark < leftmark: + done = True + else: + temp = alist[leftmark] + alist[leftmark] = alist[rightmark] + alist[rightmark] = temp + + temp = alist[first] + alist[first] = alist[rightmark] + alist[rightmark] = temp + + return rightmark + +alist = [54,26,93,17,77,31,44,55,20] +quickSort(alist) +print(alist) \ No newline at end of file