This code is meant to sort a list of integers in place using quick sort.
I'm doing this to improve my style and to improve my knowledge of fundamental algorithms/data structures for an upcoming coding interview.
def quicksort(l):
quicksort_helper(l, 0, len(l)-1)
def quicksort_helper(l, lo, hi):
if lo >= hi:
return
pivot_ind = partition(l, lo, hi)
quicksort_helper(l, lo, pivot_ind-1)
quicksort_helper(l, pivot_ind+1, hi)
def partition(l, lo, hi):
pivot = l[hi]
left = lo
for right in range(lo, hi):
if l[right] <= pivot:
swap(l, left, right)
left += 1
swap(l, left, hi)
pivot_ind = left
return pivot_ind
def swap(l, i, j):
temp = l[i]
l[i] = l[j]
l[j] = temp