Created
December 9, 2018 17:53
-
-
Save wilcoln/8bbe858e2468fb7f84e69feb0d4c22e4 to your computer and use it in GitHub Desktop.
Quick sort in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def partition(a,p,r): | |
pivot = p | |
for i in range(p+1,r+1): | |
if(a[i]<a[pivot]): | |
tmp = a[i] | |
a[i] = a[pivot+1] | |
a[pivot+1] = a[pivot] | |
a[pivot] = tmp | |
pivot = pivot + 1 | |
return pivot | |
def quickSort(a,p,r): | |
if(r>p): | |
q = partition(a, p, r) | |
quickSort(a,p,q-1) | |
quickSort(a,q+1,r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment