Skip to content

Instantly share code, notes, and snippets.

@scriptpapi
Forked from bcambel/quicksort.py
Last active May 23, 2018 17:23
Show Gist options
  • Save scriptpapi/b507ccd04114a5565b3656cfd980cdea to your computer and use it in GitHub Desktop.
Save scriptpapi/b507ccd04114a5565b3656cfd980cdea to your computer and use it in GitHub Desktop.
Simple quick sort implementation
import random
def quickSort(iList):
print("ALL", iList)
if len(iList) <= 1:
return iList
else:
left = quickSort([x for x in iList[1:] if x<iList[0]])
middle = [iList[0]]
right = quickSort([x for x in iList[1:] if x>=iList[0]])
print("LMR", left, middle, right)
return left + middle + right
testList = random.sample(range(1, 100), 20)
print(testList)
print(quickSort(testList))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment