112 |
112 |
113 UcxList *ucx_list_sort_merge(int length, |
113 UcxList *ucx_list_sort_merge(int length, |
114 UcxList* restrict ls, UcxList* restrict le, UcxList* restrict re, |
114 UcxList* restrict ls, UcxList* restrict le, UcxList* restrict re, |
115 cmp_func fnc, void* data) { |
115 cmp_func fnc, void* data) { |
116 |
116 |
117 ucx_dynarray_new(UcxList*, sorted, length); |
117 UcxList** sorted = (UcxList**) malloc(sizeof(UcxList*)*length); |
118 UcxList *rc, *lc; |
118 UcxList *rc, *lc; |
119 |
119 |
120 lc = ls; rc = le; |
120 lc = ls; rc = le; |
121 int n = 0; |
121 int n = 0; |
122 while (lc && lc != le && rc != re) { |
122 while (lc && lc != le && rc != re) { |
145 sorted[i]->next = sorted[i+1]; |
145 sorted[i]->next = sorted[i+1]; |
146 } |
146 } |
147 sorted[length-1]->next = NULL; |
147 sorted[length-1]->next = NULL; |
148 |
148 |
149 UcxList *ret = sorted[0]; |
149 UcxList *ret = sorted[0]; |
150 ucx_dynarray_free(sorted); |
150 free(sorted); |
151 return ret; |
151 return ret; |
152 } |
152 } |
153 |
153 |
154 UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data) { |
154 UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data) { |
155 if (l == NULL) { |
155 if (l == NULL) { |