From 19165991ab797521ddc8a54b3d29bcd10c01b820 Mon Sep 17 00:00:00 2001 From: apoorv tikalkar Date: Mon, 15 Oct 2018 18:01:47 +0530 Subject: [PATCH] Create quicksort.py --- quicksort.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 quicksort.py diff --git a/quicksort.py b/quicksort.py new file mode 100644 index 0000000..d1837bc --- /dev/null +++ b/quicksort.py @@ -0,0 +1,30 @@ +def partition(arr,low,high): + i = ( low-1 ) + pivot = arr[high] + + for j in range(low , high): + + + if arr[j] <= pivot: + + + i = i+1 + arr[i],arr[j] = arr[j],arr[i] + + arr[i+1],arr[high] = arr[high],arr[i+1] + return ( i+1 ) + +def quickSort(arr,low,high): + if low < high: + pi = partition(arr,low,high) + quickSort(arr, low, pi-1) + quickSort(arr, pi+1, high) + +arr = [10, 7, 8, 9, 1, 5] +n = len(arr) +quickSort(arr,0,n-1) +print ("Sorted array is:") +for i in range(n): + print ("%d" %arr[i]), + +