赞
踩
- GList *
- g_list_sort (GList *list,
- GCompareFunc compare_func)
- {
- return g_list_sort_real (list, (GFunc) compare_func, NULL);
-
- }
- static GList*
- g_list_sort_real (GList *list,
- GFunc compare_func,
- gpointer user_data)
- {
- GList *l1, *l2;
-
- if (!list)
- return NULL;
- if (!list->next)
- return list;
-
- l1 = list;
- l2 = list->next;
-
-
- while ((l2 = l2->next) != NULL)
- {
- if ((l2 = l2->next) == NULL)
- break;
- l1 = l1->next;
- }
- l2 = l1->next; // 指向链表中间节点
- l1->next = NULL;
-
-
- return g_list_sort_merge (g_list_sort_real (list, compare_func, user_data),
- g_list_sort_real (l2, compare_func, user_data),
- compare_func,
- user_data)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。