Hacker News new | past | comments | ask | show | jobs | submit login

The following C-code heap sorts integers t[1]...t[j] in ascending order:

        for (i = j/2; j > 1; t[l] = k) {
                if (i) k = t[i--]; else { k = t[j]; t[j--] = t[1]; }
                for (l = i + 1; (m = l + l) <= j; t[l] = t[m], l = m) {
                        if (m < j && t[m] < t[m+1]) m++;
                        if (t[m] <= k) break;
                }
        }



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: