8000 Merge pull request #19 from NevilleAntony98/patch-1 · jeffmikels/python@bdc5906 · GitHub
[go: up one dir, main page]

Skip to content

Commit bdc5906

Browse files
authored
Merge pull request AllAlgorithms#19 from NevilleAntony98/patch-1
Created Quick Sort
2 parents 71ad34a + b1c544c commit bdc5906

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

sorting/quick_sort.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#quick sort implementation in Python by Neville Antony
2+
3+
def partition(arr, down, up):
4+
i = ( down - 1 )
5+
pivot = arr[up]
6+
7+
for j in range(down, up):
8+
if arr[j] <= pivot:
9+
i = i+1
10+
arr[i],arr[j] = arr[j],arr[i]
11+
12+
arr[i+1],arr[up] = arr[up],arr[i+1]
13+
return ( i+1 )
14+
15+
def quickSort(arr, down, up):
16+
if down< up:
17+
pi = partition(arr, down, up)
18+
quickSort(arr, down, pi-1)
19+
quickSort(arr, pi+1, up)
20+
21+
arr = [91, 72, 68, 23, 37, 55]
22+
n = len(arr)
23+
quickSort(arr,0,n-1)
24+
print("The sorted array is :")
25+
for i in range(n):
26+
print ("%d" %arr[i]),
27+

0 commit comments

Comments
 (0)
0