Last active
November 5, 2017 06:47
-
-
Save death667b/fcde95f725447dd7f8615aa9ce5d3c50 to your computer and use it in GitHub Desktop.
Playing with python3 - just a simple quick sort algo. This code has 6 basic operations for 15 numbers in the array.
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
""" | |
Quick Sort algo in Python3 | |
""" | |
def quick_sort(arr): | |
""" | |
quick_sort sorts an array of integers. | |
""" | |
if len(arr) <= 1: | |
return arr | |
pivot = arr[len(arr) // 2] | |
left = [x for x in arr if x < pivot] | |
middle = [x for x in arr if x == pivot] | |
right = [x for x in arr if x > pivot] | |
return quick_sort(left) + middle + quick_sort(right) | |
print(quick_sort([4, 2, 7, 9, 5, 1, 7, 1, 43, -5, 1, 76, -3421, 5, 7])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment