diff options
| author | Tyge Lovset <[email protected]> | 2022-12-20 23:31:51 +0100 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2022-12-20 23:31:51 +0100 |
| commit | 5f57d597cd27aef55adbcb3b452973b0c6e33667 (patch) | |
| tree | dfd59c2fd0e36a6ef37912a9d0cc5a65970f1524 /misc/examples/list_splice.c | |
| parent | 1763be8c8cbbc0896477fcf924edd4180d1345a9 (diff) | |
| download | STC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.tar.gz STC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.zip | |
Restructured folders: examples, benchmarks, tests into misc folder.
Diffstat (limited to 'misc/examples/list_splice.c')
| -rw-r--r-- | misc/examples/list_splice.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/misc/examples/list_splice.c b/misc/examples/list_splice.c new file mode 100644 index 00000000..f7bac0d6 --- /dev/null +++ b/misc/examples/list_splice.c @@ -0,0 +1,43 @@ +#include <stdio.h> + +#define i_val int +#define i_tag i +#define i_extern // define _clist_mergesort() once +#include <stc/clist.h> + +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_auto (clist_i, list1, list2) + { + c_forlist (i, int, {1, 2, 3, 4, 5}) + clist_i_push_back(&list1, *i.ref); + + c_forlist (i, int, {10, 20, 30, 40, 50}) + clist_i_push_back(&list2, *i.ref); + + print_ilist("list1:", list1); + print_ilist("list2:", list2); + + clist_i_iter it = clist_i_advance(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); + } +} |
