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)
45 snode *p = slist_raw_prev(l, n);
46 slist_remove_after(l, p);
65 for (int i=1; i<=10; i++)
67 struct x *x = alloca(sizeof(*x));
70 slist_add_head(&l, &x->n);
72 slist_add_tail(&l, &x->n);
76 SLIST_WALK_DELSAFE(x, l, prev)
78 slist_remove_after(&l, &prev->n);
80 slist_remove(&l, &x->n);
81 SLIST_FOR_EACH(struct x *, x, l)
82 printf("%d/", x->val);