[prev] 21 [next]

Bubble Sort

Simple adaptive method:
  • make multiple passes from N to i (i=0..N-1)
  • on each pass, swap any out-of-order adjacent pairs
  • elements move until they meet a smaller element
  • eventually smallest element moves to i th position
  • repeat until all elements have moved to appropriate position
  • stop if there are no swaps during one pass (already sorted)