Created
May 28, 2021 10:11
-
-
Save anonymousmaharaj/d1a54dcc8373406ba8a212303ee474dc to your computer and use it in GitHub Desktop.
qsort
This file contains hidden or 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 qsort(arr): | |
if len(arr) < 2: | |
return arr | |
else: | |
pivot = arr[0] | |
less = [i for i in arr if i < pivot] | |
mid = [i for i in arr if i == pivot] | |
great = [i for i in arr if i > pivot] | |
return qsort(less) + mid + qsort(great) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment