Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void sort(struct linked_list *list,
- int (*cmp)(const void *, const void *))
- {
- size_t slice_size = 1;
- for(; slice_size < list->size; slice_size *= 2)
- {
- struct node *tail = list->first;
- while(tail)
- {
- struct node *head = tail;
- size_t count = slice_size;
- while(tail && count--) // performance killer
- tail = tail->next;
- count = slice_size;
- while(head != tail && tail && count)
- {
- if(cmp(head->data, tail->data) <= 0)
- head = head->next;
- else
- {
- struct node *node = tail;
- tail = tail->next;
- remove_node(node, list);
- insert_before(node, list, head);
- --count;
- }
- }
- while(tail && count--) // performance killer
- tail = tail->next;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement