def quicksort(aList, start, last):
i = start + 1
j = start + 1
pivot = aList[start]
while j <= last:
if pivot > aList[j]:
temp = aList[i]
aList[i] = aList[j]
aList[j] = temp
i = i + 1
j = j + 1
temp = aList[start]
aList[start] = aList[i-1]
aList[i-1] = temp
if i - start > 2:
quicksort(aList, start, i-2)
if last - i > 0:
quicksort(aList, i, last)
try this!
yopy have given another version of quick sort.
the key of quick sort is the choose of pivot, in your code the pivot is the first element of array, to get a better average performance, you can choose pivot by random.