📜  如何在 python 堆栈溢出中冒泡搜索 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:48.249000             🧑  作者: Mango

代码示例1
mylist = [12, 5, 13, 8, 9, 65]

def bubble(badList):
    length = len(badList) - 1
    unsorted = True

    while unsorted:
        for element in range(0,length):
            unsorted = False
            if badList[element] > badList[element + 1]:
                hold = badList[element + 1]
                badList[element + 1] = badList[element]
                badList[element] = hold
                print badList
            else:
                unsorted = True

print bubble(mylist)