每日一算法(持续更新)

# 冒泡排序
def pop(list1):
    hight = len(list1) - 1
    while hight > 0:
        for i in range(0, hight):
            if list1[i] > list1[i + 1]:
                list1[i], list1[i + 1] = list1[i + 1], list1[i]
        hight -= 1
    return list1


# 鸡尾酒排序
def cooktallsort(list1):
    flag = True
    for i in range(len(list1) // 2):
        if flag:
            flag = False
            for j in range(i, len(list1) - i - 1):
                if list1[j] > list1[j + 1]:
                    list1[j], list1[j + 1] = list1[j + 1], list1[j]
                    flag = True

            for j in range(len(list1) - i - 1, i, -1):
                if list1[j] < list1[j - 1]:
                    list1[j], list1[j - 1] = list1[j - 1], list1[j]
                    flag = True
        else:
            break
    return list1

你可能感兴趣的:(每日一算法(持续更新))