ucx/list.c

changeset 69
fb59270b1de3
parent 67
27e67e725d35
child 73
f15c7d6aebb9
equal deleted inserted replaced
68:88dbea299440 69:fb59270b1de3
111 } 111 }
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 UcxList *sorted[length]; 116
117 ucx_dynarray_new(UcxList*, sorted, length);
117 UcxList *rc, *lc; 118 UcxList *rc, *lc;
118 119
119 lc = ls; rc = le; 120 lc = ls; rc = le;
120 int n = 0; 121 int n = 0;
121 while (lc && lc != le && rc != re) { 122 while (lc && lc != le && rc != re) {
143 for (int i = 0 ; i < length-1 ; i++) { 144 for (int i = 0 ; i < length-1 ; i++) {
144 sorted[i]->next = sorted[i+1]; 145 sorted[i]->next = sorted[i+1];
145 } 146 }
146 sorted[length-1]->next = NULL; 147 sorted[length-1]->next = NULL;
147 148
148 return sorted[0]; 149 UcxList *ret = sorted[0];
150 ucx_dynarray_free(sorted);
151 return ret;
149 } 152 }
150 153
151 UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data) { 154 UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data) {
152 if (l == NULL) { 155 if (l == NULL) {
153 return NULL; 156 return NULL;

mercurial