alist = [3,1,2,9,0,7,4,8,5,6]
def quickSort(alist,start,end):
if start >= end:
return
index = start
privior = alist[index]
low = start
hight = end
while low < hight:
while alist[hight] >= privior and low < hight :
hight = hight - 1
while alist[low] <= privior and low < hight :
low = low + 1
if low < hight:
temp = alist[low]
alist[low] = alist[hight]
alist[hight] = temp
alist[index] = alist[low]
alist[low] = privior
quickSort(alist,start,low)
quickSort(alist,low+1,end)
if __name__ == '__main__':
quickSort(alist,0,9)
astr = ''
for item in alist:
astr = astr + str(item)
astr = astr + ' '
print(astr)
alist = [3,1,2,9,0,7,4,8,5,6]
def qs(alist,start,end):
if start >= end:
return
indexList = []
indexList.append(start)
indexList.append(end)
while len(indexList) > 0:
priviorIndex = indexList[0]
privior = alist[indexList[0]]
low = indexList[0]
hight = indexList[1]
while low < hight:
while alist[hight] >= privior and low < hight:
hight = hight - 1
while alist[low] <= privior and low < hight:
low = low + 1
if low < hight:
temp = alist[low]
alist[low] = alist[hight]
alist[hight] = temp
alist[priviorIndex] = alist[low]
alist[low] = privior
if low > indexList[0]:
indexList.append(indexList[0])
indexList.append(low)
if hight < indexList[1]:
indexList.append(low + 1)
indexList.append(indexList[1])
indexList.pop(0)
indexList.pop(0)
if __name__ == '__main__':
qs(alist,0,9)
astr = ''
for item in alist:
astr = astr + str(item)
astr = astr + ' '
print(astr)