Singly-Linked List#
Singly-linked List module provides APIs to handle singly-linked list operations such as insert, push, pop, push back, sort and remove.
Note
The pop operation follows FIFO method.
Singly-Linked List module Usage#
Modules#
Functions#
Initialize a singly-linked list.
Add given item at beginning of the list.
Add item at the end of the list.
Remove and return the first element of the list.
Insert an item after the given item.
Remove an item from the list.
Sort list items.
Checks if the list is empty.
Function Documentation#
sl_slist_init#
void sl_slist_init (sl_slist_node_t ** head)
Initialize a singly-linked list.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_slist_node_t ** | N/A | head | Pointer to pointer of head element of list. |
sl_slist_push#
void sl_slist_push (sl_slist_node_t ** head, sl_slist_node_t * item)
Add given item at beginning of the list.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_slist_node_t ** | N/A | head | Pointer to pointer of head element of the list. |
sl_slist_node_t * | N/A | item | Pointer to an item to add. |
sl_slist_push_back#
void sl_slist_push_back (sl_slist_node_t ** head, sl_slist_node_t * item)
Add item at the end of the list.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_slist_node_t ** | N/A | head | Pointer to the pointer of a head element of the list. |
sl_slist_node_t * | N/A | item | Pointer to the item to add. |
sl_slist_pop#
sl_slist_node_t * sl_slist_pop (sl_slist_node_t ** head)
Remove and return the first element of the list.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_slist_node_t ** | N/A | head | Pointer to he pointer of the head element of the list. |
Returns
Pointer to item that was at top of the list.
sl_slist_insert#
void sl_slist_insert (sl_slist_node_t * item, sl_slist_node_t * pos)
Insert an item after the given item.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_slist_node_t * | N/A | item | Pointer to an item to add. |
sl_slist_node_t * | N/A | pos | Pointer to an item after which the item to add will be inserted. |
sl_slist_remove#
void sl_slist_remove (sl_slist_node_t ** head, sl_slist_node_t * item)
Remove an item from the list.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_slist_node_t ** | N/A | head | Pointer to pointer of the head element of list. |
sl_slist_node_t * | N/A | item | Pointer to the item to remove. |
sl_slist_sort#
void sl_slist_sort (sl_slist_node_t ** head, bool(*)(sl_slist_node_t *item_l, sl_slist_node_t *item_r) cmp_fnct)
Sort list items.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_slist_node_t ** | N/A | head | Pointer to the pointer of the head element of the list. |
bool(*)(sl_slist_node_t *item_l, sl_slist_node_t *item_r) | N/A | cmp_fnct | Pointer to function to use for sorting the list. item_l Pointer to left item. item_r Pointer to right item. Returns whether the two items are ordered (true) or not (false). |
sl_slist_is_empty#
static bool sl_slist_is_empty (sl_slist_node_t * head)
Checks if the list is empty.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_slist_node_t * | N/A | head | Pointer to the head element of the list. |