g_[s]list_qsort suggestion
- From: dramboz imaginet fr
- To: gtk-list redhat com
- Subject: g_[s]list_qsort suggestion
- Date: Fri, 5 Jun 1998 19:34:48 +0200 (CEST)
Hello,
What about adding a function to quickly sort GLists
and GSLists ?
Here's a simple implementation using qsort :
typedef gint (*GQSortFunc) ( const gpointer value1,
const gpointer value2);
GList*
g_list_qsort( GList *list, GQSortFunc func) {
GList *item;
gpointer *base, *tmp;
guint size;
g_return_val_if_fail( list != NULL, list);
g_return_val_if_fail( func != NULL, list);
size = g_list_length( list);
base = tmp = g_malloc( size*sizeof( gpointer));
g_return_val_if_fail( base != NULL, list);
item = list;
while ( item) {
*tmp++ = item->data;
item = item->next;
}
qsort( base, size, sizeof( gpointer), func);
tmp = base;
item = list;
while ( item) {
item->data = *tmp++;
item = item->next;
}
g_free( base);
return list;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]