4 ms·
Vaguely remember seeing this in the first few chapters somewhere of Spirit of C by Mullish and Cooper.
by carlsborg 4y ago
Vaguely remember seeing this in the first few chapters somewhere of Spirit of C by Mullish and Cooper.
- petercooper 4y agoCan confirm. It's on page 243, in the "Arrays" chapter, and is referred to as the "exchange sort." The actual code is: /* Sort the array for (i = 0; i < array_size - 1; i++) for (j = i + 1; j < array_size; j++) if (array[i] > array[j]]) { int temp = array[i]; array[i] = array[j]: array[j] = temp; } So that's from the late 80s.
- Jtsummers 4y agoThat's not the same sort as in the article. Two key differences: 1. j in the article runs from 0 to array_size-1 (if done in C like this, in the article it's a 1-based array so 1 to array_size). This sort has j run from i+1 to array_size-1. 2. The swap condition is reversed. In the article's sort the swap happens when array[i] < array[j].