python实现快速排序

def sortList(alist):
    alen = len(alist)
    if alen == 0:
        return alist
    if alen > 0:
        aitem = alist[alen / 2]
        aleftlist = []
        arightlist = []
        for i in range(0,alen):
            afirstitem = alist[i]
            if i <> alen / 2:
                if afirstitem > aitem:
                    arightlist.append(afirstitem)
                else:
                    aleftlist.append(afirstitem)
        aleftlist = sortList(aleftlist)
        arightlist = sortList(arightlist)
        aleftlist.append(aitem)
        return aleftlist + arightlist

alist = [0,1,2]
print(sortList(alist))

你可能感兴趣的:(python,快速排序)