I'm trying to learn how to create a standalone recursive quicksort function in Python but I'm having trouble. I'm tasked with accepting a single argument, the unsorted list, and partitioning the list for recursion within the same quicksort function.
def quicksort(copyLyst):
low = len(copyLyst) - len(copyLyst)
high = len(copyLyst) - 1
# Base Case
if high <= low:
return
center = low + (high - low) // 2
pivot = copyLyst[center]
first = low
last = high
# Partitioning
done = False
while not done:
while copyLyst[first] < pivot:
first = first + 1
while pivot < copyLyst[last]:
last = last - 1
if first >= last:
done = True
else:
swap = copyLyst[first]
copyLyst[first] = copyLyst[last]
copyLyst[last] = swap
first = first + 1
last = last - 1
leftCopy = copyLyst[low:last + 1]
quicksort(leftCopy)
rightCopy = copyLyst[last + 1:high]
quicksort(rightCopy)
I'm hoping to keep much of my original code as I can, because I'm still learning about data structures and I think that would help me the best conceptually.
I've tried adjusting the range on the left and right recursive calls, I tried rewriting the entire function in new variables, I've double checked that the index locations don't conflict.
I've gone through everything compared to my textbook. I don't know what I did wrong.