We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 86a33e3 + c87382a commit 970c227Copy full SHA for 970c227
1 file changed
Quick_sort_Python.py
@@ -0,0 +1,30 @@
1
+# https://www.facebook.com/harsith.gayle.1/posts/2784315391846205
2
+# Subscribed by Code House
3
+
4
5
+def partition(arr,low,high):
6
+ i = ( low-1 )
7
+ pivot = arr[high] # pivot element
8
+ for j in range(low , high):
9
+ # If current element is smaller
10
+ if arr[j] <= pivot:
11
+ # increment
12
+ i = i+1
13
+ arr[i],arr[j] = arr[j],arr[i]
14
+ arr[i+1],arr[high] = arr[high],arr[i+1]
15
+ return ( i+1 )
16
+# sort
17
+def quickSort(arr,low,high):
18
+ if low < high:
19
+ # index
20
+ pi = partition(arr,low,high)
21
+ # sort the partitions
22
+ quickSort(arr, low, pi-1)
23
+ quickSort(arr, pi+1, high)
24
+# main
25
+arr = [2,5,3,8,6,5,4,7]
26
+n = len(arr)
27
+quickSort(arr,0,n-1)
28
+print ("Sorted array is:")
29
+for i in range(n):
30
+ print (arr[i],end=" ")
0 commit comments