C singly linked list.
More...
#include <stdbool.h>
Go to the source code of this file.
|
enum | linkedlist_ret_t { LL_SUCCESS = 0,
LL_ERR_APPEND = 1,
LL_ERR_NOT_FOUND = 2
} |
|
◆ LINKEDLIST_FOREACH
#define LINKEDLIST_FOREACH |
( |
|
LL, |
|
|
|
VALUE_TYPE, |
|
|
|
CODE |
|
) |
| |
Value: { \
node_t* curr = LL->root; \
while(curr != NULL) { \
VALUE_TYPE* value = (VALUE_TYPE*) curr->value; \
CODE \
curr = curr->next; \
} \
}
Helper macro to loop through each linked list value.
- Note
- A variable value will be available that is casted to the underlying type for the void* in the node given via the VALUE_TYPE parameter.
- Parameters
-
LL | - Linked list to loop through |
VALUE_TYPE | - Type to cast the void* to |
CODE | - Code block to execute for each node |
◆ node_t
◆ linkedlist_ret_t
Return types for the linked list.
◆ linkedlist_add()
Add new item onto the end of the linked list.
- Parameters
-
ll | - Linked list |
node | - Node to be appended |
- Returns
linkedlist_ret_t
◆ linkedlist_destroy()
Destroy the given linked list freeing all of its memory (including all of the node's memory).
- Parameters
-
ll | - Linked list to destroy |
◆ linkedlist_get_at()
Get node at index from the linked list.
- Parameters
-
ll | - Linked list |
idx | - Index from which to get the element |
- Returns
node_t
, or NULL if not found
◆ linkedlist_new()
Create a new linked list.
- Returns
linkedlist_t
, or NULL if an error occurs
◆ linkedlist_node_new()
node_t* linkedlist_node_new |
( |
void * |
value, |
|
|
void(*)(void *) |
free_fn |
|
) |
| |
Create a new node for the linked list.
◆ linkedlist_remove_at()
Remove item at the given index from the linked list.
- Parameters
-
ll | - Linked list |
idx | - Index at which to remove a node |