def qsort(array): if len(array) <= 1: return array pivot=array.pop() leftarray = [i for i in array if i < pivot] rightarray = [i for i in array if i >= pivot] return qsort(leftarray)+[pivot]+qsort(rightarray) a = [1,2,7,321,46323,213,1] print(qsort(a))
递归写法很好理解
栈的实现