Exchange Sort

Systematic comparisons globally.

Best O(n^2) Avg O(n^2) Worst O(n^2) Space O(1) Stable No In-place Yes Comparison-based

How it works

Systematic comparisons globally.

Implementation

function exchangeSort(arr) {
  for (let i = 0; i < arr.length - 1; i++)
    for (let j = i + 1; j < arr.length; j++)
      if (arr[i] > arr[j])
        [arr[i], arr[j]] = [arr[j], arr[i]];
}