Bubble Sort Algorithm

說明

氣泡排序法(bubble sort)是排序演算法(sorting algorithm)中較簡易的一種。
其運作的原理是藉由逐次比較相鄰的兩筆資料,並依照排序條件(由大至小或由小至大)交換資料直到排序完成為止。

展示

 

演算法

Function bubbleSort(Type data[1..n])
    Index i, j;
    For i = 1 to n do
          For j = i+1 to n do
              If data[j] > data[j + 1] then
                   swap data[i] and data[j]
End

程式碼

 

其他排序法可參閱:排序法