diff options
| author | _Tradam <[email protected]> | 2023-09-08 01:29:47 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-08 01:29:47 +0000 |
| commit | 3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd (patch) | |
| tree | afbe4b540967223911f7c5de36559b82154f02f3 /misc/examples/linkedlists/list_erase.c | |
| parent | 0841165881871ee01b782129be681209aeed2423 (diff) | |
| parent | 1a72205fe05c2375cfd380dd8381a8460d9ed8d1 (diff) | |
| download | STC-modified-modified.tar.gz STC-modified-modified.zip | |
Diffstat (limited to 'misc/examples/linkedlists/list_erase.c')
| -rw-r--r-- | misc/examples/linkedlists/list_erase.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/misc/examples/linkedlists/list_erase.c b/misc/examples/linkedlists/list_erase.c new file mode 100644 index 00000000..211c5a5d --- /dev/null +++ b/misc/examples/linkedlists/list_erase.c @@ -0,0 +1,30 @@ +// erasing from clist +#include <stdio.h> + +#define i_type IList +#define i_key int +#include <stc/clist.h> + +int main(void) +{ + IList L = c_init(IList, {10, 20, 30, 40, 50}); + + c_foreach (x, IList, L) + printf("%d ", *x.ref); + puts(""); + // 10 20 30 40 50 + IList_iter it = IList_begin(&L); // ^ + IList_next(&it); + it = IList_erase_at(&L, it); // 10 30 40 50 + // ^ + IList_iter end = IList_end(&L); // + IList_next(&it); + it = IList_erase_range(&L, it, end); // 10 30 + // ^ + printf("list contains:"); + c_foreach (x, IList, L) + printf(" %d", *x.ref); + puts(""); + + IList_drop(&L); +} |
