ExchangeSort

ExchangeSort sort is an exchange sorts that works as follows: The item at index 0 is compared with each subsequent item in the list at index 1, 2, ..., N-1. For each comparison, if the subsequent item is smaller than the element at index 0, the two entries are exchanged. Repeat this process with index 1, index 2 and so on up to index N-2.

ExchangeSort pseudo-code:

   // assume we have an array 'a' with 'n' elements

   for (cur_i = 0, limit = n-1; cur_i < limit; cur_i++) {
      for (next_i = cur_i+1; next_i < n; next_i++) {
         if (COMPARE (a, next_i, cur_i))
            SWAP (a, next_i, cur_i);
      }
   }