Skip to content

Instantly share code, notes, and snippets.

@death667b
Last active November 5, 2017 06:47
Show Gist options
  • Save death667b/fcde95f725447dd7f8615aa9ce5d3c50 to your computer and use it in GitHub Desktop.
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.
"""
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