Last active
December 13, 2019 06:54
-
-
Save SuvroBaner/80c5d0732ccc2ed6fcd34eedfd19dc87 to your computer and use it in GitHub Desktop.
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
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