1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 21:08:08 +01:00

added sorting

This commit is contained in:
kojima
2000-03-29 19:01:31 +00:00
parent fb51ee83b7
commit 7bb187a3b3

View File

@@ -684,11 +684,36 @@ static void *replaceInBag(WMBag *self, int index, void *item)
static int sortBag(WMBag *self, int (*comparer)(const void*, const void*)) static int sortBag(WMBag *self, int (*comparer)(const void*, const void*))
{ {
assert(0&&"not implemented"); void **items;
W_Node *tmp;
int i;
items = wmalloc(sizeof(void*)*SELF->count);
i = 0;
return 0; tmp = treeMinimum(SELF->root, SELF->nil);
while (tmp != SELF->nil) {
items[i++] = tmp->data;
tmp = treeSuccessor(tmp, SELF->nil);
}
qsort(&items[0], SELF->count, sizeof(void*), comparer);
i = 0;
tmp = treeMinimum(SELF->root, SELF->nil);
while (tmp != SELF->nil) {
tmp->index = i;
tmp->data = items[i++];
tmp = treeSuccessor(tmp, SELF->nil);
}
wfree(items);
return 1;
} }