Last active
October 12, 2023 17:52
-
-
Save muromtsev/75baa92b8f14bcf513c4ad099e5145bb to your computer and use it in GitHub Desktop.
Quick sort
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
def quicksort(arr): | |
if len(arr) < 2: | |
return arr | |
else: | |
pivot = arr[0] | |
less = [i for i in arr[1:] if i < pivot] | |
greater = [i for i in arr[1:] if i > pivot] | |
return quicksort(less) + [pivot] + quicksort(greater) | |
print(quicksort([10, 5, 2, 3])) # [2, 3, 5, 10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment