diff options
Diffstat (limited to 'nss/test_slist.c')
-rw-r--r-- | nss/test_slist.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/nss/test_slist.c b/nss/test_slist.c new file mode 100644 index 0000000..138adf4 --- /dev/null +++ b/nss/test_slist.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> + +#include "slist.h" + +struct node { + int id; + struct slist list; +}; + +void node_init(struct node* self) { + self->id = 0; + slist_init(&self->list); +} + +void node_print(struct node* self) { + printf("node %d\n", self->id); +} + +int find_two(struct node* self) { + if (self->id == 2) return 0; else return 1; +} + +int main() { + struct node h, a, b, c; + node_init(&h); a.id = 0; + node_init(&a); a.id = 1; + node_init(&b); b.id = 2; + node_init(&c); c.id = 3; + slist_extend(&h.list, &a.list); + slist_extend(&a.list, &b.list); + slist_extend(&b.list, &c.list); + + slist_for(struct node, list, &h, &node_print); + slist_search(struct node, list, &h, found, not_found, &find_two); + +found: + printf("found two\n"); + return 0; + +not_found: + printf("two not found\n"); + return 1; +} |