4 void list_mergesort(struct list_head
*head
,
5 int (*compare
)(const struct list_head
*, const struct list_head
*))
8 struct list_head
*unsorted_head
, *sorted_head
, *p
, *q
, *tmp
;
9 int psize
, qsize
, K
, count
;
18 p
= unsorted_head
->next
;
24 if (q
== unsorted_head
)
33 if (q
== unsorted_head
)
35 if (psize
== 0 && qsize
== 0)
37 if (!psize
|| (qsize
&& compare(p
, q
) > 0)) {
47 list_add_tail(e
, sorted_head
);
51 } while (p
!= unsorted_head
);
54 head
->next
= sorted_head
->next
;
55 head
->prev
= sorted_head
->prev
;
56 sorted_head
->prev
->next
= head
;
57 sorted_head
->next
->prev
= head
;
61 unsorted_head
= sorted_head
;