08/08/14 17:29:32
>>182
list_t *list_sort(list_t *list, int (*cmp_func) (const data_t, const data_t))
{
list_t *i, *j, *next, *item, *tmp;
list_t head;
head.next = list;
for (i = &head; i->next; i = next) {
next = i->next;
for (j = &head; j->next != i->next; j = j->next) {
if (cmp_func(i->next->data, j->next->data) < 0) {
item = i->next;
i->next = i->next->next;
tmp = j->next;
j->next = item;
item->next = tmp;
break;
}
}
}
return head.next;
}