Skip to content

Instantly share code, notes, and snippets.

@jamescasia
Created March 12, 2022 16:11
Show Gist options
  • Save jamescasia/9a149049da4d15d8b28be5a249f65f32 to your computer and use it in GitHub Desktop.
Save jamescasia/9a149049da4d15d8b28be5a249f65f32 to your computer and use it in GitHub Desktop.
Quick sort algorithm
def quicksort(arr):
if len(arr) == 1:
return arr
if len(arr) == 0:
return []
pivot = arr[-1]
left = []
right = []
for a in arr[:-1]:
if a > pivot:
right.append(a)
else:
left.append(a)
left = quicksort(left)
right = quicksort(right)
return left+[pivot]+right
arr = [5, 2, 4, 3, 1, 8, 7, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment