| static void *get_next(const void *a) |
| return ((const struct line *)a)->next; |
| static void set_next(void *a, void *b) |
| ((struct line *)a)->next = b; |
| static int compare_strings(const void *a, const void *b) |
| const struct line *x = a, *y = b; |
| return strcmp(x->text, y->text); |
| int main(int argc, char **argv) |
| struct line *line, *p = NULL, *lines = NULL; |
| struct strbuf sb = STRBUF_INIT; |
| if (strbuf_getwholeline(&sb, stdin, '\n')) |
| line = xmalloc(sizeof(struct line)); |
| line->text = strbuf_detach(&sb, NULL); |
| lines = llist_mergesort(lines, get_next, set_next, compare_strings); |
| printf("%s", lines->text); |