<menu id="guoca"></menu>
<nav id="guoca"></nav><xmp id="guoca">
  • <xmp id="guoca">
  • <nav id="guoca"><code id="guoca"></code></nav>
  • <nav id="guoca"><code id="guoca"></code></nav>

    冒泡排序 python 代碼


    發現錯別字 1年前 提問
    回答
    1
    瀏覽
    10419
    請勿發布不友善或者負能量的內容。與人為善,比聰明更重要!
    回答數量: 1
    等保高級測評師 NISP

    冒泡排序(英語:Bubble Sort)是一種簡單的排序算法。它重復地遍歷要排序的數列,一次比較兩個元素,如果他們的順序錯誤就把他們交換過來。遍歷數列的工作是重復地進行直到沒有再需要交換,也就是說該數列已經排序完成。

    python冒泡排序是一種簡單的簡單列訪問排序,代碼如下:

    def bubble_sort(list):
        n = len(list)
        for j in range(n - 1):
            count = 0
            for i in range(0, n - 1 - j):
                if list[i] > list[i + 1]:
                    list[i], list[i + 1] = list[i + 1], list[i]
                    count += 1
            if count == 0:
                break

    回答所涉及的環境:聯想天逸510S、Windows 10。

    1年前 / 評論
    亚洲 欧美 自拍 唯美 另类