|
C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
|
Singly-linked list of int.
More...
#include <stdbool.h>#include <stddef.h>Go to the source code of this file.
Classes | |
| struct | linked_list_t |
| struct | ll_node |
Macros | |
| #define | LL_NOT_FOUND ((size_t)-1) |
Typedefs | |
| typedef struct ll_node | ll_node_t |
Functions | |
| linked_list_t * | ll_create (void) |
| void | ll_destroy (linked_list_t *list) |
| size_t | ll_find (const linked_list_t *list, int value) |
| bool | ll_is_empty (const linked_list_t *list) |
| bool | ll_pop_front (linked_list_t *list, int *out_value) |
| bool | ll_push_back (linked_list_t *list, int value) |
| bool | ll_push_front (linked_list_t *list, int value) |
| void | ll_reverse (linked_list_t *list) |
| size_t | ll_size (const linked_list_t *list) |
Singly-linked list of int.
Designed for clarity over performance. Owns its nodes — ll_destroy frees every node. Caller never touches the node struct directly; all operations go through the list handle.
| Operation | Time |
|---|---|
| push_front | O(1) |
| push_back | O(n) (no tail pointer cached) |
| pop_front | O(1) |
| find | O(n) |
| size | O(1) (cached) |
Definition in file linked_list.h.
| #define LL_NOT_FOUND ((size_t)-1) |
Definition at line 49 of file linked_list.h.
| linked_list_t * ll_create | ( | void | ) |
Definition at line 8 of file linked_list.c.
References linked_list_t::head, and linked_list_t::size.
Referenced by main().
| void ll_destroy | ( | linked_list_t * | list | ) |
Definition at line 16 of file linked_list.c.
References linked_list_t::head, and ll_node::next.
Referenced by main().
| size_t ll_find | ( | const linked_list_t * | list, |
| int | value | ||
| ) |
Returns the index of value, or (size_t)-1 if missing.
Definition at line 66 of file linked_list.c.
References linked_list_t::head, and LL_NOT_FOUND.
Referenced by main().
| bool ll_is_empty | ( | const linked_list_t * | list | ) |
Definition at line 79 of file linked_list.c.
References linked_list_t::size.
| bool ll_pop_front | ( | linked_list_t * | list, |
| int * | out_value | ||
| ) |
Definition at line 56 of file linked_list.c.
References linked_list_t::head, ll_node::next, linked_list_t::size, and ll_node::value.
| bool ll_push_back | ( | linked_list_t * | list, |
| int | value | ||
| ) |
Definition at line 38 of file linked_list.c.
References linked_list_t::head, ll_node::next, linked_list_t::size, and ll_node::value.
Referenced by main().
| bool ll_push_front | ( | linked_list_t * | list, |
| int | value | ||
| ) |
Definition at line 27 of file linked_list.c.
References linked_list_t::head, ll_node::next, linked_list_t::size, and ll_node::value.
| void ll_reverse | ( | linked_list_t * | list | ) |
Reverses the list in place. O(n).
Definition at line 83 of file linked_list.c.
References linked_list_t::head, and ll_node::next.
Referenced by main().
| size_t ll_size | ( | const linked_list_t * | list | ) |
Definition at line 75 of file linked_list.c.
References linked_list_t::size.
Referenced by print_list().