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/cw/code/tokenizer/ads/dll | |
parent | 2e239a4ed2265f7c7dc2aabedfdb7d7b011704cb (diff) |
write up update
Diffstat (limited to 'comp/cw/code/tokenizer/ads/dll')
-rw-r--r-- | comp/cw/code/tokenizer/ads/dll/Makefile | 5 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dll/dll.c | 62 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dll/dll.h | 19 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dll/dll.o | bin | 2424 -> 0 bytes | |||
-rwxr-xr-x | comp/cw/code/tokenizer/ads/dll/dlltest | bin | 20640 -> 0 bytes | |||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dll/dlltest.c | 20 |
6 files changed, 0 insertions, 106 deletions
diff --git a/comp/cw/code/tokenizer/ads/dll/Makefile b/comp/cw/code/tokenizer/ads/dll/Makefile deleted file mode 100644 index 651681d..0000000 --- a/comp/cw/code/tokenizer/ads/dll/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -all: dll.c - cc dll.c -c -o dll.o - -test: all - cc dll.o dlltest.c -o dlltest diff --git a/comp/cw/code/tokenizer/ads/dll/dll.c b/comp/cw/code/tokenizer/ads/dll/dll.c deleted file mode 100644 index b24b13f..0000000 --- a/comp/cw/code/tokenizer/ads/dll/dll.c +++ /dev/null @@ -1,62 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -typedef struct dll_t dll_t; - -typedef struct dll_t { - void *data; - dll_t *next; - dll_t *prev; -} dll_t; - -dll_t *dllalloc(){ - dll_t *output = malloc(sizeof(dll_t)); - if (output == NULL) - return NULL; - output->next = NULL; - output->prev = NULL; - return output; -} - -void dllsetdata(dll_t *node, void *data){ - node->data = malloc(sizeof(data)); - memcpy(node->data, data, sizeof(data)); -} - -void dllsetnext(dll_t *node, dll_t *next){ - if (node->next == NULL) { - node->next = next; - node->next->prev = node; - } - else - dllsetnext(node->next, next); -} -void dllsetprev(dll_t *node, dll_t *prev){ - if (node->prev == NULL) { - node->prev = prev; - node->prev->next = node; - } - else - dllsetprev(node->prev, prev); -} - -void *dllgetat(dll_t *head, int index){ - if (index == 0) - return head->data; - else { - if (head->next != NULL) { - return dllgetat(head->next, index - 1); - }else { - return NULL; - } - } -} - -void dllfreeall(dll_t *head){ - if (head->next != NULL) - dllfreeall(head->next); - free(head->data); - free(head); -} - diff --git a/comp/cw/code/tokenizer/ads/dll/dll.h b/comp/cw/code/tokenizer/ads/dll/dll.h deleted file mode 100644 index 44940ce..0000000 --- a/comp/cw/code/tokenizer/ads/dll/dll.h +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -typedef struct dll_t dll_t; - -typedef struct dll_t { - void *data; - dll_t *next; - dll_t *prev; -} dll_t; - -dll_t *dllalloc(); -void dllsetdata(dll_t *node, void *data); -void dllsetnext(dll_t *node, dll_t *next); -void dllsetprev(dll_t *node, dll_t *prev); -void *dllgetat(dll_t *head, int index); -void dllfreeall(dll_t *head); - diff --git a/comp/cw/code/tokenizer/ads/dll/dll.o b/comp/cw/code/tokenizer/ads/dll/dll.o Binary files differdeleted file mode 100644 index 2c9a145..0000000 --- a/comp/cw/code/tokenizer/ads/dll/dll.o +++ /dev/null diff --git a/comp/cw/code/tokenizer/ads/dll/dlltest b/comp/cw/code/tokenizer/ads/dll/dlltest Binary files differdeleted file mode 100755 index 83f900c..0000000 --- a/comp/cw/code/tokenizer/ads/dll/dlltest +++ /dev/null diff --git a/comp/cw/code/tokenizer/ads/dll/dlltest.c b/comp/cw/code/tokenizer/ads/dll/dlltest.c deleted file mode 100644 index 4544d2e..0000000 --- a/comp/cw/code/tokenizer/ads/dll/dlltest.c +++ /dev/null @@ -1,20 +0,0 @@ -#include <stdio.h> - -#include "dll.h" - -int main(){ - dll_t *head = dllalloc(); - dllsetdata(head, "hello"); - - for (int i = 0; i < 3; i++){ - dll_t *node = dllalloc(); - dllsetdata(node, "hi"); - dllsetnext(head, node); - } - - for (int i = 0; i < 4; i++) - printf("%s\n", (char *)dllgetat(head, i)); - printf("%s\n", (char *)head->prev->next->data); - - dllfreeall(head); -} |