Skip to content

Instantly share code, notes, and snippets.

@ideasman42
ideasman42 / linked_list_sort.c
Created May 23, 2015 06:10
Mergesort single linked list (improvements from SE answer)
/* Originally from: http://stackoverflow.com/a/27663998/432509
*
* With following modifications:
* - Use a pointer to the tail (remove 2x conditional checks, reduces code-size).
* - Avoid re-assigning empty values the size doesn't change.
* - Corrected comments.
*/
static void *listbase_sort_impl(struct Link *head, int (*cmp)(const void *, const void *))
{