Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why not use insertion sort - as an on-line algorithm, it can be used to immediately sort the list as it's build.

The implementation is straight-forward: instead of appending new elements to the end of the list, insert them in the correct place.

My personal go-to algorithm for linked lists is an unstable merge-sort variant with explicit stack[1] - while not as simple as insertion sort, performance is far superior.

[1] https://bitbucket.org/cggaertner/listsort/src/master/listsor...




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: