Python实现快速排序算法

#-*-encoding:utf-8-*-
import sys,random,time
reload(sys)
sys.setdefaultencoding('utf8')
def singleSort(list,start,end):
    if start>=end:
        return -1
    pivotPos = start
    pivot = list[pivotPos]
    low = start
    high = end
    while low<high:
        while list[high]>=pivot and low<high:
            high = high-1
        if low>=high: 
            return pivotPos
        exchange(list,pivotPos,high)
        pivotPos=high
        while list[low]<=pivot and low<high:
            low = low+1
        if low>=high: 
            return pivotPos
        exchange(list,pivotPos,low)
        pivotPos=low
def exchange(list,pos1,pos2):
    temp = list[pos1]
    list[pos1] = list[pos2]
    list[pos2] = temp
def qsort(list,low,high):
    pivotpos = singleSort(list,low,high)
    if pivotpos<0:
        return
    qsort(list,low,pivotpos-1)
    qsort(list,pivotpos+1,high)
def generateRandList(num):
    list=[]
    random.seed()
    for x in range(num):
        list.append(random.randint(0,65535))
    return list
if __name__ == '__main__':
     list = generateRandList(10000)
     #list=[4,8,2,3,7,9]
    qsort(list,0,len(list)-1)
    print list