active_list_clear(head);
free(head);
}
-
-/*
- * Using insert sort.
- * Note. the list should not be large, or it will be very inefficient.
- *
- */
-struct active_list *active_list_sort(struct active_list *head,
- int (*compare) (const void *,
- const void *))
-{
- struct active_list tmphead;
- struct active_list *node, *ptr;
- if (!head)
- return NULL;
- active_list_init(&tmphead);
- for (node = active_list_next(head, NULL); node;
- node = active_list_next(head, NULL)) {
- if (tmphead.node.next == &tmphead.node) {
- active_list_move_node(head, &tmphead, node);
- } else {
- for (ptr = active_list_next(&tmphead, NULL); ptr;
- ptr = active_list_next(&tmphead, ptr)) {
- if (compare(ptr, node) <= 0) {
- break;
- }
- }
- if (!ptr) {
- active_list_move_node(head, &tmphead, node);
- } else {
- active_list_move_node(head, ptr, node);
- }
- }
- node->depended = &tmphead;
- }
- for (ptr = active_list_prev(&tmphead, NULL); ptr;
- ptr = active_list_prev(&tmphead, NULL)) {
- active_list_move_node(&tmphead, head, ptr);
- }
- return head;
-}
struct active_list *new_head,
struct active_list *node);
-struct active_list *active_list_sort(struct active_list *head,
- int (*compare_fcn_t) (const void *,
- const void *));
-
struct active_list *active_list_next(struct active_list *head,
struct active_list *ptr);
active_test_add(head, O);
}
-static int active_test_compare(const void *a, const void *b)
-{
- struct active_list *first = (struct active_list *)a;
- struct active_list *second = (struct active_list *)b;
- return memcmp(list_entry(first, struct active_test, list),
- list_entry(second, struct active_test, list),
- sizeof(struct active_test));
-}
-
static void show_list(struct active_list *head)
{
struct active_list *ptr;
test = list_entry(ptr, struct active_test, list);
printf("%s ", test->str);
}
- printf("\npos order after sort: ");
- active_list_sort(&head, &active_test_compare);
- show_list(&head);
-
printf("after clear: ");
active_list_clear(&head);
for (ptr = active_list_next(&head, NULL); ptr;