A doubly-linked list. More...
#include <stdbool.h>Go to the source code of this file.
Data Structures | |
| struct | ListNode |
| A single entry in a List. More... | |
| struct | List |
| A doubly-linked list. More... | |
| struct | ListItr |
| An iterator into a list. More... | |
Macros | |
| #define | MAX_LIST_NODES 128 |
| Number of reserved list nodes. | |
| #define | LIST_DEFAULT { .head = NULL, .tail = NULL, .len = 0 } |
| Default list declaration for empty lists. | |
Typedefs | |
| typedef struct ListNode | ListNode |
| typedef struct List | List |
| A doubly-linked list. | |
Enumerations | |
| enum | ListItrDirection { LIST_ITR_FORWARD , LIST_ITR_REVERSE } |
| ListItr direction More... | |
Functions | |
| List | list_init (void) |
| void | list_clear (List *list) |
| bool | list_is_empty (const List *list) |
| void | list_push_front (List *list, void *data) |
| void | list_push_back (List *list, void *data) |
| void | list_insert (List *list, void *data, unsigned int idx) |
| bool | list_swap (List *list, unsigned int idx_a, unsigned int idx_b) |
| void * | list_get_at_idx (List *list, unsigned int idx) |
| bool | list_remove_at_idx (List *list, unsigned int idx) |
| bool | list_remove_data (List *list, void *data) |
| int | list_get_len (const List *list) |
| ListItr | list_itr_create (List *list) |
| ListItr | rev_list_itr_create (List *list) |
| void * | list_itr_next (ListItr *itr) |
| void | list_itr_remove_current_node (ListItr *itr) |
A doubly-linked list.
Definition in file list.h.
| #define LIST_DEFAULT { .head = NULL, .tail = NULL, .len = 0 } |
| #define MAX_LIST_NODES 128 |
| enum ListItrDirection |
| void list_clear | ( | List * | list | ) |
| void * list_get_at_idx | ( | List * | list, |
| unsigned int | idx | ||
| ) |
| int list_get_len | ( | const List * | list | ) |
| List list_init | ( | void | ) |
Initialize a list.
Set the values of a list to default.
If using this function to reset a list, the list must be freed with list_clear to ensure the list's nodes are deleted properly.
| void list_insert | ( | List * | list, |
| void * | data, | ||
| unsigned int | idx | ||
| ) |
Insert data into a List a specific index
If the index specified is larger than the length of the list it will list_push_back() the data instead;
Performs the following operation:
┌─────┐
│ node│
└─────┘
┌─────┐ ┌─────┐ ┌─────┐
│idx-1│◄─►│ idx │◄─►│idx+1│
└─────┘ └─────┘ └─────┘
node prev to the node at idx - 1node next to the node at idxnext to new nodeprev to the new nodeResult:
┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ │idx-1│◄─►│ node│◄─►│ idx │◄─►│idx+1│ └─────┘ └─────┘ └─────┘ └─────┘
Finally, the list is now updated with new node now at the labeled idx:
┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ │idx-1│◄─►│ idx │◄─►│idx+1│◄─►│idx+2│ └─────┘ └─────┘ └─────┘ └─────┘
| bool list_is_empty | ( | const List * | list | ) |
| void * list_itr_next | ( | ListItr * | itr | ) |
| void list_itr_remove_current_node | ( | ListItr * | itr | ) |
Remove the current ListNode from the iterator.
The "current node" corresponds to the list node associated with the most recently returned valu from list_itr_next()
| itr | pointer to the ListItr |
| void list_push_back | ( | List * | list, |
| void * | data | ||
| ) |
| void list_push_front | ( | List * | list, |
| void * | data | ||
| ) |
| bool list_remove_at_idx | ( | List * | list, |
| unsigned int | idx | ||
| ) |
| bool list_remove_data | ( | List * | list, |
| void * | data | ||
| ) |
| bool list_swap | ( | List * | list, |
| unsigned int | idx_a, | ||
| unsigned int | idx_b | ||
| ) |