Skip to content

Instantly share code, notes, and snippets.

@larsr larsr/quicksort in python
Last active Dec 11, 2015

Embed
What would you like to do?
def quicksort(l):
work = [(0,len(l)-1)]
while work:
(left,right) = work.pop()
if right < left:
continue
i_piv = left
piv = l[i_piv]
l0,r0 = left, right
while left<right:
while l[left] <= piv and left < right: left += 1
while l[right] > piv: right -= 1
if left < right: l[left], l[right] = l[right], l[left]
l[i_piv], l[right] = l[right], piv
work.append((l0,right-1))
work.append((right+1,r0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.