Skip to content

Instantly share code, notes, and snippets.

@wilcoln
Created December 9, 2018 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilcoln/8bbe858e2468fb7f84e69feb0d4c22e4 to your computer and use it in GitHub Desktop.
Save wilcoln/8bbe858e2468fb7f84e69feb0d4c22e4 to your computer and use it in GitHub Desktop.
Quick sort in python
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