快速排序的方法
代码:
def my_rank1(arr):Maxarr1 = []Minarr1 = []if len(arr) < 2:return arrfor x in arr[1:]:if x > arr[0]:Maxarr1.append(x)elif x <= arr[0]:Minarr1.append(x)return my_rank1(Minarr1) + [arr[0]] + my_rank1(Maxarr1)
输入:
list1 = [54, 5, 5, 41, 64, 64, 634, 1]
print(my_rank1(list1))
结果:
[1, 5, 5, 41, 54, 64, 64, 634]Process finished with exit code 0