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>
This commit is contained in:
Lukas Fleischer 2011-06-18 19:43:13 +00:00
parent b2645847a0
commit 9c3a8a5a49

View File

@ -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;