3 void sort(struct list_head
*head
, void *d
, int (*cmp
)(void *, const struct list_head
*, const struct list_head
*)) {
5 struct list_head
*unsorted_head
, *sorted_head
, *p
, *q
, *tmp
;
6 int psize
, qsize
, K
, count
;
15 p
= unsorted_head
->next
;
21 if (q
== unsorted_head
)
30 if (q
== unsorted_head
)
32 if (psize
== 0 && qsize
== 0)
34 if (!psize
|| (qsize
&& cmp(d
, p
, q
) > 0)) {
44 list_add_tail(e
, sorted_head
);
48 } while (p
!= unsorted_head
);
51 head
->next
= sorted_head
->next
;
52 head
->prev
= sorted_head
->prev
;
53 sorted_head
->prev
->next
= head
;
54 sorted_head
->next
->prev
= head
;
58 unsorted_head
= sorted_head
;