基本的快排算法,二分法
#!/usr/bin/env python
# encoding: utf-8 l1=[1,4,2,6,3] def path_sort(l,start_index,end_index):
flag = l[end_index]
i = start_index - 1
for j in range(start_index,end_index):
if l[j] > flag:
pass
else:
i += 1
tmp = l[i]
l[i] = l[j]
l[j] = tmp
tmp = l[end_index]
l[end_index] = l[i+1]
l[i+1] = tmp return i+1 def quick_sort(l,start_index,end_index):
if start_index >= end_index:
return
middle = path_sort(l,start_index,end_index)
quick_sort(l,start_index,middle-1)
quick_sort(l,middle+1,end_index)
print l,len(l) quick_sort(l1,0,len(l1)-1)
fastsort.py