Hacker News new | ask | show | jobs
by petercooper 1446 days ago
Can 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.
1 comments

That'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].