diff options
| author | Tyge Løvset <[email protected]> | 2021-04-22 15:18:29 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-04-22 15:18:29 +0200 |
| commit | c67a87749fb02c32e982dd309f62b54c1efde076 (patch) | |
| tree | 731bb22bb4ab37968577853a9464433977e39f4e /examples | |
| parent | 0dfe69fa5dd7d4d9dded93d35106537e1ea76243 (diff) | |
| download | STC-modified-c67a87749fb02c32e982dd309f62b54c1efde076.tar.gz STC-modified-c67a87749fb02c32e982dd309f62b54c1efde076.zip | |
clist_X_splice*() now returns updated input iter. Added list_splice.c example.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/list_splice.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/list_splice.c b/examples/list_splice.c new file mode 100644 index 00000000..06464c27 --- /dev/null +++ b/examples/list_splice.c @@ -0,0 +1,34 @@ +#include <stc/clist.h> +#include <stdio.h> + +using_clist(i, int); + +void print_ilist(const char* s, clist_i list) +{ + printf("%s", s); + c_foreach (i, clist_i, list) { + printf(" %d", *i.ref); + } + puts(""); +} + +int main () +{ + c_init (clist_i, list1, { 1, 2, 3, 4, 5 }); + c_init (clist_i, list2, { 10, 20, 30, 40, 50 }); + + clist_i_iter_t it = clist_i_fwd(clist_i_begin(&list1), 2); + it = clist_i_splice(&list1, it, &list2); + + puts("After splice"); + print_ilist("list1:", list1); + print_ilist("list2:", list2); + + clist_i_splice_range(&list2, clist_i_begin(&list2), &list1, it, clist_i_end(&list1)); + + puts("After splice_range"); + print_ilist("list1:", list1); + print_ilist("list2:", list2); + + c_del(clist_i, &list1, &list2); +}
\ No newline at end of file |
