diff options
author | standenboy <standenboy@seacrossedlovers.xyz> | 2024-04-30 14:22:45 +0100 |
---|---|---|
committer | standenboy <standenboy@seacrossedlovers.xyz> | 2024-04-30 14:22:45 +0100 |
commit | c460a26850eca5ded047d0eb0d183b861087aa53 (patch) | |
tree | 000c4a117746de71870fbee820809f7df49bcfcf /comp/lucas-standen-NEA/code/ads/ll/ll.c | |
parent | 2e239a4ed2265f7c7dc2aabedfdb7d7b011704cb (diff) |
write up update
Diffstat (limited to 'comp/lucas-standen-NEA/code/ads/ll/ll.c')
-rw-r--r-- | comp/lucas-standen-NEA/code/ads/ll/ll.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/comp/lucas-standen-NEA/code/ads/ll/ll.c b/comp/lucas-standen-NEA/code/ads/ll/ll.c new file mode 100644 index 0000000..ba0a0df --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/ll/ll.c @@ -0,0 +1,57 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +typedef struct ll_t ll_t; + +typedef struct ll_t { + void *data; + ll_t *next; +} ll_t; + +ll_t *llalloc(){ + ll_t *output = malloc(sizeof(ll_t)); + if (output == NULL) + return NULL; + output->next = NULL; + return output; +} + +void llsetdata(ll_t *node, void *data){ + node->data = malloc(sizeof(data)); + memcpy(node->data, data, sizeof(data)); +} + +void llsetnext(ll_t *node, ll_t *next){ + if (node->next == NULL) + node->next = next; + else + llsetnext(node->next, next); +} + +void *llgetat(ll_t *head, int index){ + if (index == 0) + return head->data; + else { + if (head->next != NULL) { + return llgetat(head->next, index - 1); + }else { + return NULL; + } + } +} + +ll_t *llgetendnode(ll_t *head){ + if (head->next == NULL) + return head; + else + return llgetendnode(head->next); +} + +void llfreeall(ll_t *head){ + if (head->next != NULL) + llfreeall(head->next); + free(head->data); + free(head); +} + |