From 7bb187a3b38cfbee0a217b829c6ccd0c30a44af7 Mon Sep 17 00:00:00 2001 From: kojima Date: Wed, 29 Mar 2000 19:01:31 +0000 Subject: [PATCH] added sorting --- WINGs/bagtree.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/WINGs/bagtree.c b/WINGs/bagtree.c index 5d8eb672..7e45c0e3 100644 --- a/WINGs/bagtree.c +++ b/WINGs/bagtree.c @@ -684,11 +684,36 @@ static void *replaceInBag(WMBag *self, int index, void *item) + 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; } -- 2.11.4.GIT