'''
Created on 2017-1-6
@author: admin
'''
def quickSort(source,start,end):
if start==end:
return
index=shuffle(source, start, end)
if(index-1>start):
quickSort(source, start,index-1)
if index+1<=end:
quickSort(source, index+1, end)
def shuffle(source,start,end):
leftIndex=start;
rightIndex=end
sepValue=source[start]
directionRight=True
while leftIndex!=rightIndex:
if directionRight:
if sepValue>source[rightIndex]:
source[leftIndex]=source[rightIndex]
leftIndex=leftIndex+1
directionRight=False
else:
rightIndex=rightIndex-1
else:
if sepValue<=source[leftIndex]:
source[rightIndex]=source[leftIndex]
rightIndex=rightIndex-1
directionRight=True
else:
leftIndex+=1
source[leftIndex]=sepValue;
return leftIndex
if __name__ == '__main__':
source=[7,3,2,9,4,8,5,6,1]
quickSort(source,0,len(source)-1)
for i in range(0,len(source)):
print(source[i],end=',')