2 * UCW Library -- Single-Linked Lists
4 * (c) 2005 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include "lib/slists.h"
14 slist_raw_prev(slist *l, snode *n)
28 slist_prev(slist *l, snode *n)
30 snode *p = slist_raw_prev(l, n);
31 return (p == &l->head) ? NULL : p;
35 slist_insert_before(slist *l, snode *what, snode *before)
38 slist_raw_prev(l, before)->next = what;
42 slist_remove(slist *l, snode *n)
44 snode *p = slist_raw_prev(l, n);
45 slist_remove_after(l, p);
63 for (int i=1; i<=10; i++)
65 struct x *x = alloca(sizeof(*x));
68 slist_add_head(&l, &x->n);
70 slist_add_tail(&l, &x->n);
74 SLIST_WALK_DELSAFE(x, l, prev)
76 slist_remove_after(&l, &prev->n);
78 slist_remove(&l, &x->n);
79 SLIST_FOR_EACH(struct x *, x, l)
80 printf("%d/", x->val);