351:87c22ec6a0fd | 360:fed2ead878ea |
---|---|
204 } | 204 } |
205 | 205 |
206 return s; | 206 return s; |
207 } | 207 } |
208 | 208 |
209 static UcxList *ucx_list_sort_merge(int length, | 209 static UcxList *ucx_list_sort_merge(size_t length, |
210 UcxList* ls, UcxList* le, UcxList* re, | 210 UcxList* ls, UcxList* le, UcxList* re, |
211 cmp_func fnc, void* data) { | 211 cmp_func fnc, void* data) { |
212 | 212 |
213 UcxList** sorted = (UcxList**) malloc(sizeof(UcxList*)*length); | 213 UcxList** sorted = (UcxList**) malloc(sizeof(UcxList*)*length); |
214 UcxList *rc, *lc; | 214 UcxList *rc, *lc; |
215 | 215 |
216 lc = ls; rc = le; | 216 lc = ls; rc = le; |
217 int n = 0; | 217 size_t n = 0; |
218 while (lc && lc != le && rc != re) { | 218 while (lc && lc != le && rc != re) { |
219 if (fnc(lc->data, rc->data, data) <= 0) { | 219 if (fnc(lc->data, rc->data, data) <= 0) { |
220 sorted[n] = lc; | 220 sorted[n] = lc; |
221 lc = lc->next; | 221 lc = lc->next; |
222 } else { | 222 } else { |
253 if (l == NULL) { | 253 if (l == NULL) { |
254 return NULL; | 254 return NULL; |
255 } | 255 } |
256 | 256 |
257 UcxList *lc; | 257 UcxList *lc; |
258 int ln = 1; | 258 size_t ln = 1; |
259 | 259 |
260 UcxList *ls = l, *le, *re; | 260 UcxList *ls = l, *le, *re; |
261 | 261 |
262 // check how many elements are already sorted | 262 // check how many elements are already sorted |
263 lc = ls; | 263 lc = ls; |
269 | 269 |
270 if (le == NULL) { | 270 if (le == NULL) { |
271 return l; // this list is already sorted :) | 271 return l; // this list is already sorted :) |
272 } else { | 272 } else { |
273 UcxList *rc; | 273 UcxList *rc; |
274 int rn = 1; | 274 size_t rn = 1; |
275 rc = le; | 275 rc = le; |
276 // skip already sorted elements | 276 // skip already sorted elements |
277 while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) { | 277 while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) { |
278 rc = rc->next; | 278 rc = rc->next; |
279 rn++; | 279 rn++; |