python冒泡排序与插入排序,快速排序

# 冒泡排序

a = [3,6,87,21,1,34,6,45]
b = []
for i in range(len(a)-1):
    for j in range(len(a)-i-1):
        if a[i]<a[j+i+1]:
            t = a[i]
            a[i] = a[j+1+i]
            a[j+1+i] = t
print(a)

# 插入排序
a = [3,6,87,21,1,34,6,45,45,43,23,76]
for i in range(1,len(a)):
    k = a[i]
    for j in range(i)[::-1]:
        if k<a[j]:
            a[j+1] = a[j]
            a[j] = k
print(a)
#quick sort
def quickSort(L, low, high):
    i = low
    j = high
    if i >= j:
        return L
    key = L[i]
    while i < j:
        while i < j and L[j] >= key:
            j = j-1
        L[i] = L[j]
        while i < j and L[i] <= key:
            i = i+1
        L[j] = L[i]
    L[i] = key
    quickSort(L, low, i-1)
    quickSort(L, j+1, high)
    return L

你可能感兴趣的:(python冒泡排序与插入排序,快速排序)