Created
March 8, 2016 20:08
-
-
Save kbendick/31b6be3cf9379d3cd3fe to your computer and use it in GitHub Desktop.
Simple implementation of quicksort 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
import random | |
R = random.Random(42) | |
def qsort(L): | |
if len(L) < 2: return L | |
i = R.randrange(len(L)) # Just some random index in the list. | |
return qsort([x for x in L if x < L[i]]) + [x for x in L if x == L[i]] + qsort([x for x in L if x > L[i]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment