# 递归实现快速排序 def quickSort(mylist,Min,Max): if(Min < Max): listMin = Min; listMax = Max; temNum = mylist[listMin]; while (listMin != listMax) : while (listMin < listMax and mylist[listMax] >= temNum) : listMax = listMax - 1 ; if listMin < listMax: mylist[listMin] = mylist[listMax]; listMin = listMin + 1 ; while (listMin < listMax and mylist[listMin] <= temNum) : listMin = listMin + 1 ; if listMin < listMax: mylist[listMax] = mylist[listMin]; mylist[listMin] = temNum ; for i in range(Min,Max,1): quickSort(mylist,Min,listMin-1); # 向左排序 quickSort(mylist,listMin + 1, Max); # 向右排序 return 0; if __name__ == '__main__': # 递归实现快速排序 mylist=[]; maxList = int(input("请输入总共有多少个数值: ")) ; for i in range(0,maxList,1) : print("请输入第",i+1,"个排序的数值: ",end="") mylist.append(int(input())); quickSort(mylist,0,len(mylist)-1); print("排序的结果为:"); print(mylist);