Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
linked_list.h
Go to the documentation of this file.
1
66#ifndef _LINKED_LIST_H
67#define _LINKED_LIST_H
68
69#include <stdint.h>
70#include <stdbool.h>
71
76typedef struct node
77{
78 void* val;
79 struct node* next;
80 struct node* prev;
82
86typedef struct
87{
90 int length;
91} list_t;
92
93void push(list_t* list, void* val);
94void* pop(list_t* list);
95void unshift(list_t* list, void* val);
96void* shift(list_t* list);
97bool addIdx(list_t* list, void* val, uint16_t index);
98void addBefore(list_t* list, void* val, node_t* entry);
99void addAfter(list_t* list, void* val, node_t* entry);
100void* removeIdx(list_t* list, uint16_t index);
101void* removeEntry(list_t* list, node_t* entry);
102void clear(list_t* list);
103
104#ifdef TEST_LIST
105// Exercise the linked list functions
106void listTester(void);
107#endif
108
109#endif
void * removeEntry(list_t *list, node_t *entry)
Definition linked_list.c:375
struct node * next
The next node in the list.
Definition linked_list.h:79
void unshift(list_t *list, void *val)
Add to the front of the list.
Definition linked_list.c:110
void * removeIdx(list_t *list, uint16_t index)
Remove at an index in the list.
Definition linked_list.c:311
struct node * prev
The previous node in the list.
Definition linked_list.h:80
node_t * last
The last node in the list.
Definition linked_list.h:89
void addBefore(list_t *list, void *val, node_t *entry)
Insert a value into the list immediately before the given node.
Definition linked_list.c:235
struct node node_t
A node in a doubly linked list with pointers to the previous and next values (which may be NULL),...
void addAfter(list_t *list, void *val, node_t *entry)
Insert a value into the list immediately after the given node.
Definition linked_list.c:274
void clear(list_t *list)
Remove all items from the list.
Definition linked_list.c:429
void * shift(list_t *list)
Remove from the front of the list.
Definition linked_list.c:138
int length
The number of nodes in the list.
Definition linked_list.h:90
void * val
A pointer to the data for this node.
Definition linked_list.h:78
bool addIdx(list_t *list, void *val, uint16_t index)
Add at an index in the list.
Definition linked_list.c:180
void push(list_t *list, void *val)
Add to the end of the list.
Definition linked_list.c:42
node_t * first
The first node in the list.
Definition linked_list.h:88
void * pop(list_t *list)
Remove from the end of the list.
Definition linked_list.c:70
A doubly linked list with pointers to the first and last nodes.
Definition linked_list.h:87
A node in a doubly linked list with pointers to the previous and next values (which may be NULL),...
Definition linked_list.h:77