快速排序和冒泡排序

def quick_sort(b):
    if len(b) < 2:
        return b
    mid = b[len(b)//2]
    left, right = [], []
    b.remove(mid)
    for item in b:
        if item >=mid:
            right.append(item)
        else:
            left.append(item)
    return quick_sort(left)+[mid]+quick_sort(right)
print(quickSort([4,5,3,2,4,2,12,3,7]))
def bubbleSort(list):
    for i in range(len(list)-1):
        for j in range(len(list)-1-i):
            if list[j]>list[j+1]:
                list[j],list[j+1] = list[j+1],list[j]
    return list
print(bubbleSort([4,5,3,2,4,2,12,3,7]))

你可能感兴趣的:(快速排序和冒泡排序)