Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python code for the Quick Sort Algorithm
def quicksort(x):
if len(x) == 1 or len(x) == 0:
return x
else:
pivot = x[0]
i = 0
for j in range(len(x)-1):
if x[j+1] < pivot:
x[j+1],x[i+1] = x[i+1], x[j+1]
i += 1
x[0],x[i] = x[i],x[0]
first_part = quicksort(x[:i])
second_part = quicksort(x[i+1:])
first_part.append(x[i])
return first_part + second_part
alist = [54,26,93,17,77,31,44,55,20]
quicksort(alist)
print(alist)
@RaviPabari
Copy link

RaviPabari commented Aug 19, 2020

@pete312 use pypy3 instead of python to see some BIG RUNNING TIME DIFFRENCE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment