Skip to content

Instantly share code, notes, and snippets.

@ayulockin
Created July 27, 2019 11:33
Show Gist options
  • Save ayulockin/d926e744a4d12e39f8450580e3d950b6 to your computer and use it in GitHub Desktop.
Save ayulockin/d926e744a4d12e39f8450580e3d950b6 to your computer and use it in GitHub Desktop.
:D
def quicksort(S):
if len(S)<2:
print("[RETURNED]length of list less than 2")
return
pivot = S[-1]
print("[INFO] pivot: ", pivot)
L = []
G = []
U = []
for i in S:
if i<pivot:
L.append(i)
elif i>pivot:
U.append(i)
else:
G.append(i)
print("[INFO] L: {} | U: {}".format(L, U))
quicksort(L)
quicksort(U)
merge(L, G, U, S)
def merge(L, G, U, S):
count = 0
for i in L:
S[count] = i
count+=1
S[count] = G[0]
for j in U:
S[count+1] = j
count+=1
print("[INFO] merge: ", S)
S = [10, 16, 8, 12, 15, 3, 6, 9, 2, 1, 5]
print("[INFO] unsorted list: ", S)
quicksort(S)
print("[INFO] sorted list: ", S)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment