ucx/list.c

changeset 73
f15c7d6aebb9
parent 69
fb59270b1de3
child 87
bd444539cced
equal deleted inserted replaced
72:bb3eae81aae8 73:f15c7d6aebb9
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) {

mercurial