Or working on sort things.
Bubble(A) Input: an array A, with comparison operator < on the elements and size0 ≤ A.size()
Output: A ordered by the < operator, smallest element first.
- n ← A.size()-1
- repeat
- swapped ← false
- for i ← 1 to n do
- if A[i-i] > A[i]
- Swap(A[i-1],A[i])
- swapped ← true
- n ← n - 1
- until not swapped
Insertion(A) Input: an array A, with comparison operator < on the elements and size0 ≤ A.size()
Output: A ordered by the < operator, smallest element first.
- i ← 1
- while i < A.size()
- j ← i
- while j > 0 and A[j-1] > A[j]
- Swap(A[j], A[j-1])
- j ← j - 1
- i ← i + 1