aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorjustanothercatgirl <sotov2070@gmail.com>2024-06-22 18:17:45 +0300
committerjustanothercatgirl <sotov2070@gmail.com>2024-06-23 02:52:29 +0300
commit4d68c950a12170ee9d48b1fd713e90b202f85493 (patch)
treee9b531e10c0674d6bdcd98cec0ae29944f1265ad /tests
parent57033d0ef1810abf4edd9d8e57a95a5795e5a5a9 (diff)
parentaeaf84ff54a7921195cda875492b7a22f8b0a948 (diff)
started adding `linked_list` functionality. TODO: finish split functions
Diffstat (limited to 'tests')
-rw-r--r--tests/linked_list.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/linked_list.c b/tests/linked_list.c
new file mode 100644
index 0000000..93c5f64
--- /dev/null
+++ b/tests/linked_list.c
@@ -0,0 +1,35 @@
+#define CONTAINER_IMPLEMENTATION
+#include "../include/container.h"
+#include <stdio.h>
+
+void print_linked_list(struct linked_list* list) {
+ int i = 0;
+ printf("linked list at %p, size = %zu\n", list, list->meta.assumed_size);
+ for (struct linked_list_node* current = list->first; current != NULL; current = current->next) {
+ printf("[%i] = {%i, %p}\n", i, *(int*)current->data, current->next);
+ ++i;
+ }
+}
+
+int main() {
+ struct linked_list list = ll_create(sizeof(int));
+ int a = 10;
+ ll_insert_at(&list, &a, 0);
+ a = 11;
+ ll_insert_at(&list, &a, 0);
+ a = 14;
+ ll_insert_at(&list, &a, 2);
+ ll_insert_at(&list, &a, 3);
+ ll_insert_at(&list, &a, 1);
+
+ print_linked_list(&list);
+ ll_remove_back(&list);
+ ll_remove_front(&list);
+ print_linked_list(&list);
+ ll_remove_at(&list, 1);
+ ll_remove_at(&list, 0);
+ ll_remove_at(&list, 0);
+ print_linked_list(&list);
+ ll_free(&list);
+ return 0;
+}