diff options
author | Julian T <julian@jtle.dk> | 2020-02-11 12:24:56 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-02-11 12:24:56 +0100 |
commit | 6db1a2cdd3b96731f2e092d55d8c2136eabc52d0 (patch) | |
tree | 2be8fae8ce82d708ed9f00f376dda14420850e80 /sem3/algo/mm2/linked/main.c | |
parent | 57305119e05559c1c37e903aef89cd43f44c42c9 (diff) |
Rename and cleanup
Diffstat (limited to 'sem3/algo/mm2/linked/main.c')
-rw-r--r-- | sem3/algo/mm2/linked/main.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/sem3/algo/mm2/linked/main.c b/sem3/algo/mm2/linked/main.c new file mode 100644 index 0000000..72b62cc --- /dev/null +++ b/sem3/algo/mm2/linked/main.c @@ -0,0 +1,45 @@ +#include <stdio.h> +#include "node.h" +#include "llist.h" + +void list_print(node_t *root) { + int index = 0; + /* Loop through notes and print them */ + while( root != NULL ) { + /* Print a value */ + printf("%d: %d\n", index++, root->val); + + /* Next value */ + root = root->next; + } +} + +/* Remove node */ +int main() { + + /* Do some stuff */ + llist_t list; + llist_init(&list); + + llist_append(&list, 11); // 0 + llist_append(&list, 22); // 1 + llist_append(&list, 33); // 2 + llist_append(&list, 44); // 3 + llist_append(&list, 89); // 4 + llist_append(&list, 12); // 5 + llist_append(&list, 2); // 6 + llist_append(&list, 1); // 7 + llist_append(&list, 7); // 8 + llist_append(&list, 232);// 9 + + list_print(list.root); + printf("%d\n", llist_get(&list, 5)); + llist_pop(&list, 9); + printf("%d\n", llist_get(&list, 7)); + + list_print(list.root); + + while( list.len ) { + printf("Popped %d\n", llist_pop(&list, 0)); + } +} |