Singly-Linked List

Description

Singly-linked list.

Data Structures

struct sl_slist_node_t
List node.

Functions

void sl_slist_init (sl_slist_node_t **head)
Initialize a singly-linked list.
void sl_slist_push (sl_slist_node_t **head, sl_slist_node_t *item)
Add given item at beginning of the list.
void sl_slist_push_back (sl_slist_node_t **head, sl_slist_node_t *item)
Add item at the end of the list.
sl_slist_node_t * sl_slist_pop (sl_slist_node_t **head)
Remove and return the first element of the list.
void sl_slist_insert (sl_slist_node_t *item, sl_slist_node_t *pos)
Insert an item after the given item.
void sl_slist_remove (sl_slist_node_t **head, sl_slist_node_t *item)
Remove an item from the list.
void sl_slist_sort (sl_slist_node_t **head, bool(*cmp_fnct)(sl_slist_node_t *item_l, sl_slist_node_t *item_r))
Sort list items.

Function Documentation

sl_slist_init()

void sl_slist_init ( sl_slist_node_t ** head )

Initialize a singly-linked list.

Parameters
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.

Parameters
head Pointer to pointer of head element of the list.
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.

Parameters
head Pointer to the pointer of a head element of the list.
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.

Parameters
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.

Parameters
item Pointer to an item to add.
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.

Parameters
head Pointer to pointer of the head element of list.
item Pointer to the item to remove.
Note
(1) An EFM_ASSERT is thrown if the item is not found within the list.

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.

Parameters
head Pointer to the pointer of the head element of the list.
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).