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 "ucw/slists.h"
14 slist_raw_prev(slist *l, snode *n)
27 slist_prev(slist *l, snode *n)
29 snode *p = slist_raw_prev(l, n);
30 return (p == &l->head) ? NULL : p;
34 slist_insert_before(slist *l, snode *what, snode *before)
37 slist_raw_prev(l, before)->next = what;
41 slist_remove(slist *l, snode *n)
43 snode *p = slist_raw_prev(l, n);
44 slist_remove_after(l, p);
62 for (int i=1; i<=10; i++)
64 struct x *x = alloca(sizeof(*x));
67 slist_add_head(&l, &x->n);
69 slist_add_tail(&l, &x->n);
73 SLIST_WALK_DELSAFE(x, l, prev)
75 slist_remove_after(&l, &prev->n);
77 slist_remove(&l, &x->n);
78 SLIST_FOR_EACH(struct x *, x, l)
79 printf("%d/", x->val);