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#

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

bool
sl_slist_is_empty(sl_slist_node_t *head)

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.

Parameters
N/Ahead

Pointer to pointer of head element of list.


Definition at line 80 of file platform/common/inc/sl_slist.h

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
N/Ahead

Pointer to pointer of head element of the list.

N/Aitem

Pointer to an item to add.


Definition at line 89 of file platform/common/inc/sl_slist.h

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
N/Ahead

Pointer to the pointer of a head element of the list.

N/Aitem

Pointer to the item to add.


Definition at line 99 of file platform/common/inc/sl_slist.h

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
N/Ahead

Pointer to he pointer of the head element of the list.

Returns

  • Pointer to item that was at top of the list.


Definition at line 109 of file platform/common/inc/sl_slist.h

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
N/Aitem

Pointer to an item to add.

N/Apos

Pointer to an item after which the item to add will be inserted.


Definition at line 118 of file platform/common/inc/sl_slist.h

sl_slist_remove#

void sl_slist_remove (sl_slist_node_t ** head, sl_slist_node_t * item)

Remove an item from the list.

Parameters
N/Ahead

Pointer to pointer of the head element of list.

N/Aitem

Pointer to the item to remove.


Definition at line 128 of file platform/common/inc/sl_slist.h

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
N/Ahead

Pointer to the pointer of the head element of the list.

N/Acmp_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).


Definition at line 141 of file platform/common/inc/sl_slist.h

sl_slist_is_empty#

static bool sl_slist_is_empty (sl_slist_node_t * head)

Checks if the list is empty.

Parameters
N/Ahead

Pointer to the head element of the list.


Definition at line 150 of file platform/common/inc/sl_slist.h