aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlake Romero <blake@blkrom.com>2025-10-10 17:45:11 +0100
committerBlake Romero <blake@blkrom.com>2025-10-10 17:45:34 +0100
commit9aa1e19e264b7490cf864058aa17f7e9acb41d6d (patch)
treeae3b4a2c3198c2c5c4675916c335d0939ac18fb6
parent4e36efdf20ed9f7be0c98743b6ddfa54f472c849 (diff)
Move & update main to src folder
-rw-r--r--demo/main.c45
-rw-r--r--src/main.c81
2 files changed, 81 insertions, 45 deletions
diff --git a/demo/main.c b/demo/main.c
deleted file mode 100644
index 46fce13..0000000
--- a/demo/main.c
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "../src/ll.h"
-
-int main() {
- int val = 7;
- Node* head = llnode(val);
- /* printf("Init with %i:\t", val); */
- /* llprint(head); */
-
- /* val = 12; */
- /* llpush(&head, val); */
- /* printf("Push %i:\t", val); */
- /* llprint(head); */
-
- /* val = 99; */
- /* printf("Append %i:\t", val); */
- /* llappend(head,val); */
- /* llprint(head); */
-
- /* val = 45; */
- /* printf("Insert %i:\t", val); */
- /* llinsert(&head, val, 2); */
- /* llprint(head); */
-
- /* val = 42; */
- /* printf("Insert %i:\t", val); */
- /* llinsert(&head, val, 1); */
- /* llprint(head); */
-
- /* printf("Pop %i:\t\t", llpop(&head)); */
- /* llprint(head); */
-
- /* printf("Remove %i:\t",llrmlast(&head)); */
- /* llprint(head); */
-
- /* printf("Remove %i:\t",llrm(&head,1)); */
- /* llprint(head); */
-
- /* llvprint(head); */
-
- head->next = llnode(14);
- head->next->next = llnode(22);
- llfree(&head);
- llprint(head);
- printf("Length: %i\n", lllength(head));
-}
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..8fd2d4f
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,81 @@
+#include "lib/list.h"
+#include "lib/array.h"
+
+void linkedlist_demo() {
+ int val = 7;
+ Node* head = node_init(val);
+
+ /* printf("Init with %i:\t", val); */
+ /* list_print(head); */
+
+ /* val = 12; */
+ /* list_push(&head, val); */
+ /* printf("Push %i:\t", val); */
+ /* list_print(head); */
+
+ /* val = 99; */
+ /* printf("Append %i:\t", val); */
+ /* list_append(head,val); */
+ /* list_print(head); */
+
+ /* val = 45; */
+ /* printf("Insert %i:\t", val); */
+ /* list_insert(&head, val, 2); */
+ /* list_print(head); */
+
+ /* val = 42; */
+ /* printf("Insert %i:\t", val); */
+ /* list_insert(&head, val, 1); */
+ /* list_print(head); */
+
+ /* printf("Pop %i:\t\t", list_pop(&head)); */
+ /* list_print(head); */
+
+ /* printf("Remove %i:\t",list_rmlast(&head)); */
+ /* list_print(head); */
+
+ /* printf("Remove %i:\t",list_rm(&head,1)); */
+ /* list_print(head); */
+
+ /* list_vprint(head); */
+
+ head->next = node_init(14);
+ head->next->next = node_init(22);
+ list_free(&head);
+ list_print(head);
+ printf("Length: %i\n", list_length(head));
+}
+
+void array_demo() {
+ Array a = array_init(3);
+
+ for (int i = 0; i < 10; ++i)
+ array_push(&a, i+1*2);
+
+ array_print(&a);
+
+ array_pop(&a);
+ array_pop(&a);
+ array_pop(&a);
+ array_pop(&a);
+ array_pop(&a);
+
+ array_print(&a);
+
+ /* FIX: using array after free? */
+ array_free(&a);
+ array_print(&a);
+
+ for (int i = 0; i < 10; ++i)
+ array_push(&a, i+1*2);
+
+ array_print(&a);
+
+}
+
+int main() {
+ /* linkedlist_demo(); */
+ /* array_demo(); */
+ puts("Helist_o from main");
+ return 0;
+}