版权声明:如需转载,请注明转载地址。 https://blog.csdn.net/oJohnny123/article/details/81979571
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
Created by liaoyangyang1 on 2018/8/23 下午1:41.
"""
#快速排序,递归算法 O(nlogn)
list = [4,6,7,82,27,5,4,675,4,67556,565,4]
#递归快速排序
def quicksort(list):
print('list : {0}'.format(list))
if len(list)<2:
return list #基线条件,为空或者只包含一个元素的数组是有序的
mid = list[0]#递归条件
lessmid = [i for i in list[1:] if i<=mid]#小于基准值的元素组成的子数组
biggermid = [i for i in list[1:] if i > mid]#大于基准值的元素组成的子数组
finallylist = quicksort(lessmid)+[mid]+quicksort(biggermid)
print('finallylist : {0}'.format(finallylist))
return finallylist
quicksort(list)