Skip to content

Instantly share code, notes, and snippets.

@SuvroBaner
Last active December 13, 2019 06:54
Show Gist options
  • Save SuvroBaner/80c5d0732ccc2ed6fcd34eedfd19dc87 to your computer and use it in GitHub Desktop.
Save SuvroBaner/80c5d0732ccc2ed6fcd34eedfd19dc87 to your computer and use it in GitHub Desktop.
import random
def quick_sort(array):
if len(array) <= 1: return array
pivot = random.randint(0, len(array)-1)
left, right = list(), list()
for ii in range(len(array)):
if array[ii] < array[pivot]:
left.append(array[ii])
elif array[ii] > array[pivot]:
right.append(array[ii])
elif ii < pivot:
left.append(array[ii])
else:
right.append(array[ii])
left = quick_sort(left)
right = quick_sort(right)
return left + right
arr = [9, 3, 1, 0, 3, 10, 0, 22, 16, 15]
print(quick_sort(arr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment