summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-06-18 19:43:13 +0000
committerLukas Fleischer <calcurse@cryptocrack.de>2011-06-20 19:01:30 +0200
commit9c3a8a5a49a6a66ba93596c0a022ae7ffe7fcf37 (patch)
treebffdca6b67c5750231ed3054aab99251008b3594
parentb2645847a0b1bdd585a119504333e78e7c0ce02c (diff)
downloadcalcurse-9c3a8a5a49a6a66ba93596c0a022ae7ffe7fcf37.tar.gz
calcurse-9c3a8a5a49a6a66ba93596c0a022ae7ffe7fcf37.zip
src/llist.c: Use stable insertion algorithm
Ensure the relative order of elements with equal keys is maintained when inserting into a sorted list. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/llist.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/llist.c b/src/llist.c
index b1c2df7..eeded6b 100644
--- a/src/llist.c
+++ b/src/llist.c
@@ -162,7 +162,7 @@ llist_add_sorted (llist_t *l, void *data, llist_fn_cmp_t fn_cmp)
if (!l->head)
l->head = o;
- else if (fn_cmp(o->data, l->head->data) <= 0)
+ else if (fn_cmp(o->data, l->head->data) < 0)
{
o->next = l->head;
l->head = o;
@@ -170,7 +170,7 @@ llist_add_sorted (llist_t *l, void *data, llist_fn_cmp_t fn_cmp)
else
{
i = l->head;
- while (i->next && fn_cmp(o->data, i->next->data) > 0)
+ while (i->next && fn_cmp(o->data, i->next->data) >= 0)
i = i->next;
o->next = i->next;
i->next = o;