diff options
Diffstat (limited to 'libdimension/list.c')
-rw-r--r-- | libdimension/list.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/libdimension/list.c b/libdimension/list.c index f6a1f5d..4851e94 100644 --- a/libdimension/list.c +++ b/libdimension/list.c @@ -66,7 +66,6 @@ dmnsn_list_split(dmnsn_list *list) list->length -= max; half->length = max; - return half; } @@ -84,10 +83,26 @@ dmnsn_list_sort(dmnsn_list *list, dmnsn_comparator_fn *comparator) dmnsn_list *half = dmnsn_list_split(list); dmnsn_list_sort(list, comparator); dmnsn_list_sort(half, comparator); + dmnsn_list_iterator *ii; dmnsn_list_iterator *i = list->first, *j = half->first; while (i || j) { - if (!i || (*comparator)(j, i)) { + if (!i) { + dmnsn_list_iterator *temp = dmnsn_list_next(j); + dmnsn_list_iterator_remove(half, j); + dmnsn_list_iterator_insert(list, i, j); + j = temp; + continue; + + j->prev = list->last; + list->last = j; + list->length += half->length; + half->first = half->last = NULL; + half->length = 0; + break; + } else if (!j) { + break; + } else if ((*comparator)(j, i)) { dmnsn_list_iterator *temp = dmnsn_list_next(j); dmnsn_list_iterator_remove(half, j); dmnsn_list_iterator_insert(list, i, j); |