以中轴分左右区的快速排序法:
# -*- coding: utf-8 -*-
class QuickSort:
def sort(self,list,left,right):
if(left<right):
s=list[(left+right)/2]
i=left
j=right
while(True):
while(list[i]<s):
i+=1
while(list[j]>s):
j-=1
if(i>=j):
break
self.swap(list,i,j)
self.sort(list,left,i-1)
self.sort(list,j+1,right)
else:
return
def swap(self,list,i,j):
t=list[i]
list[i]=list[j]
list[j]=t
print 'begin:'
l=[32,32,34,43,66,65,67,31,77,54,100,42]
l=list(set(l))#防止队列中含有重复数
print l
q=QuickSort()
q.sort(l,0,len(l)-1)
print l