难度:
点击显示代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import random def sort_quick(lst): """快速排序""" if len(lst) <= 1: return lst m = lst[0] left = [x for x in lst if x < m] middle = [x for x in lst if x == m] right = [x for x in lst if x > m] return sort_quick(left) + middle + sort_quick(right) lst = [random.randint(0, 10) for i in range(10)] print(lst) lst2 = sort_quick(lst) print(lst2)
1 2
[6, 1, 0, 9, 3, 7, 1, 5, 8, 10] [0, 1, 1, 3, 5, 6, 7, 8, 9, 10]
=== 全文完 ===