近来想学习一下python很算法,用python实现了一下快速排序:
#pythondef quick_sort(array, length): if length < 2 : #"array is too short to sort" return startValue = array[0] i = 0 j = length - 1 while(i < j): while(j > i): if array[j]array[j]: array[j] = array[i] --j break; i = i + 1; array[i] = startValue quick_sort(array,i) quick_sort(array[i+1:],length - i -1)array = [6,2,7,3,8,9]print("before sort array = %r" % repr(array))quick_sort(array,len(array))print("after sort array = %r" % repr(array))