diff options
| author | @syxhe <https://t.me/syxhe> | 2025-02-12 16:47:43 -0600 |
|---|---|---|
| committer | @syxhe <https://t.me/syxhe> | 2025-02-12 16:47:43 -0600 |
| commit | c1b188af8c51e29c96a0422b79516d95696869e7 (patch) | |
| tree | c6e1958727a6acc59e9c4c88240e121c274f5f28 /src/ll.h | |
| parent | 7aab85b35f884344585101aedfbd3a922bdeeb19 (diff) | |
Implement a linked list struct
Diffstat (limited to 'src/ll.h')
| -rw-r--r-- | src/ll.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/ll.h b/src/ll.h new file mode 100644 index 0000000..5e47bd9 --- /dev/null +++ b/src/ll.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #ifndef __VXGG_REWRITE___SHARED_H___28542989122405___ | ||
| 2 | #define __VXGG_REWRITE___SHARED_H___28542989122405___ | ||
| 3 | |||
| 4 | #include <stddef.h> | ||
| 5 | |||
| 6 | typedef struct dll { | ||
| 7 | void *data; | ||
| 8 | int (*dfreecb)(void*); | ||
| 9 | |||
| 10 | struct dll *next; | ||
| 11 | struct dll *prev; | ||
| 12 | } dllnode; | ||
| 13 | |||
| 14 | typedef struct { | ||
| 15 | dllnode *start; | ||
| 16 | dllnode *end; | ||
| 17 | size_t size; | ||
| 18 | } dlinkedlist; | ||
| 19 | |||
| 20 | // Initialize a dlinkedlist | ||
| 21 | void dlinkedlist_init(dlinkedlist **ll); | ||
| 22 | |||
| 23 | // Free a dlinkedlist and its elements | ||
| 24 | void dlinkedlist_free(dlinkedlist **ll); | ||
| 25 | |||
| 26 | // Insert an element to the beginning of the list | ||
| 27 | int dlinkedlist_insert(dlinkedlist * const ll, void *data, int (*dfreecb)(void*)); | ||
| 28 | |||
| 29 | // Insert an element to the end of the list | ||
| 30 | int dlinkedlist_append(dlinkedlist * const ll, void *data, int (*dfreecb)(void*)); | ||
| 31 | |||
| 32 | // Get the element from a dlinkedlist at index | ||
| 33 | dllnode *dlinkedlist_get(const dlinkedlist * const ll, size_t index); | ||
| 34 | |||
| 35 | #endif \ No newline at end of file | ||
