summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/linkedlists/list_erase.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-07-24 08:48:41 +0200
committerGitHub <[email protected]>2023-07-24 08:48:41 +0200
commit374b3c27831cd4e09461867ed231669777b96951 (patch)
tree88011006f6d536cdb1ad1eca8073392ca80687cc /misc/examples/linkedlists/list_erase.c
parent177418232a2d8a8b0df1667d3e4bd15dc37db59f (diff)
parent650b053f443f9132dadb6d1ca924c0b36849739f (diff)
downloadSTC-modified-374b3c27831cd4e09461867ed231669777b96951.tar.gz
STC-modified-374b3c27831cd4e09461867ed231669777b96951.zip
Merge pull request #65 from stclib/dev43
Dev43
Diffstat (limited to 'misc/examples/linkedlists/list_erase.c')
-rw-r--r--misc/examples/linkedlists/list_erase.c30
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);
+}