标签:blog ar for div on art log ef as
近来想学习一下python很算法,用python实现了一下快速排序:
#python def 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[i]: array[i] = array[j] ++i; break; j = j - 1; while(i < j): if array[i]>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))
标签:blog ar for div on art log ef as
原文地址:http://www.cnblogs.com/doudouyoutang/p/4101369.html