Sorting複習

1. Bubble Sort

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

FOR( i=n to 0) do:
       FOR (j = 0 to n-1 ) do:
            if (A[j] > A[j+1])
                SWAP(A[j], A[j+1])


2. Selection Sort
FOR(i=0 to n) do:
    FOR(j = i+1 to n) do:
          if (A[i] > A[j]):
              SWAP(A[i], A[j])
每次產生最小的在序列的最左邊。
3. Merge Sort
4. Bucket Sort
5. Quick Sort

留言

這個網誌中的熱門文章

面試 (網路搜尋的資源)

bitwise operation 面試考題