Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on I can’t believe that I can prove that it can sort. Parent comment
for (i=0; i<n; ++i) for (j=0; j<(i ? i : n); ++j) if (a[i] < a[j]) swap(a[i], a[j]);
However, we can go even further:
for (i=0; i<n; ++i) for (j=0; j<i; ++j) if (a[i] < a[j]) swap(a[i], a[j]);
Curiously, in such transformed form the algo echoes the 'selection sort' from my previous post, performs equivalently too (wrt ncmpr, nswp).
There are no comments on this comment yet.
However, we can go even further:
This dispenses with the explicit max swap and simply does progressive insertion.Curiously, in such transformed form the algo echoes the 'selection sort' from my previous post, performs equivalently too (wrt ncmpr, nswp).