Skip to content

Instantly share code, notes, and snippets.

@shrkw
Created September 11, 2019 07:54
Show Gist options
  • Save shrkw/4759520d1d81c73134801e6fc37a345d to your computer and use it in GitHub Desktop.
Save shrkw/4759520d1d81c73134801e6fc37a345d to your computer and use it in GitHub Desktop.
def quick_sort(src):
print(f"**: {src}")
if len(src) <= 1:
return src
pivot = src[0]
left = list()
right = list()
for n in src[1:]:
if n < pivot:
left.append(n)
else:
right.append(n)
return quick_sort(left) + [pivot] + quick_sort(right)
def sort(src):
return quick_sort(src)
if __name__ == "__main__":
import random
src = random.sample(range(3000), k=100)
print(f"init: {src}")
result = sort(src)
print(f"result: {result}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment