We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c988290 commit f9dced0Copy full SHA for f9dced0
Quick_Sort.py
@@ -0,0 +1,30 @@
1
+def partition(arr, low, high):
2
+ i = (low-1) # index of smaller element
3
+ pivot = arr[high] # pivot
4
+
5
+ for j in range(low, high):
6
7
+ # If current element is smaller than or
8
+ # equal to pivot
9
+ if arr[j] <= pivot:
10
11
+ # increment index of smaller element
12
+ i = i+1
13
+ arr[i], arr[j] = arr[j], arr[i]
14
15
+ arr[i+1], arr[high] = arr[high], arr[i+1]
16
+ return (i+1)
17
18
+def quickSort(arr, low, high):
19
+ if len(arr) == 1:
20
+ return arr
21
+ if low < high:
22
23
+ pi = partition(arr, low, high)
24
+ quickSort(arr, low, pi-1)
25
+ quickSort(arr, pi+1, high)
26
27
+arr = [6,5,4,1,8,7,3,4]
28
+n = len(arr)
29
+quickSort(arr, 0, n-1)
30
+print(arr)
0 commit comments