Compare adjacent elements. If the first one is bigger than the second one, swap them both.
Do the same for each pair of adjacent elements, starting with the first pair and ending with the last pair. At this point, the last element should be the largest number.
Repeat the above steps for all elements except the last one.
Keep repeating the above steps for fewer and fewer elements each time until there are no pairs of numbers left to compare.
var elements = [3, 1, 5, 7, 2, 4, 9, 6, 10, 8];
console.log('before: ' elements);
sort(elements);
console.log(' after: ' elements);
Time complexity: Best: O(n), Worst: O(n^2), Average: O(n^2).
Space complexity: O(1).
Stability: Stable.