Linked List
Linked List implementation in C
Functions
Linked_list

Functions

void list_init (list_t *list, size_t dataSize)
 
void list_free (list_t *list)
 
void list_destroy (list_t *list)
 
void list_push (list_t *list, const void *data)
 
void list_push_front (list_t *list, const void *data)
 
uint8_t list_pop (list_t *list, void *data)
 
uint8_t list_pop_front (list_t *list, void *data)
 
uint8_t list_get_by_index (list_t *list, uint8_t index, void *data)
 
void list_print (list_t *list, void(*printFn)(const void *data))
 
void list_for_each (list_t *list, void(*eachFn)(const void *data, void *arg), void *arg)
 
uint8_t list_size (list_t *list)
 

Detailed Description

Function Documentation

◆ list_destroy()

void list_destroy ( list_t list)

Description:

This function is used to free the memory of the linked list elements and of the mutex.

Parameters
listLinked list to free the memory of the elements and mutex.
Returns
None.

Example:

list_destroy(&list);

◆ list_for_each()

void list_for_each ( list_t list,
void(*)(const void *data, void *arg)  eachFn,
void *  arg 
)

Description:

This function is used to iterate over the elements of the list.

Parameters
listLinked list.
eachFnPointer to the function that will be executed on each element.
argArgument passed to eachFn.
Returns
None.

Example:

list_for_each(list, functionPtr, (void *) &arg);

◆ list_free()

void list_free ( list_t list)

Description:

This function is used to release the memory of the linked list elements.

Parameters
listLinked list to free the memory of its elements.
Returns
None.

Example:

list_free(&list);

◆ list_get_by_index()

uint8_t list_get_by_index ( list_t list,
uint8_t  index,
void *  data 
)

Description:

This function is used to get the value of a node at a given index. It doesn't delete the node.

Parameters
listLinked list.
indexIndex of the node.
dataPointer to the variable to which will be copied the value of the node at the given index.
Returns
1 if the given index is out of limits, 0 otherwise.

Example:

uint8_t error = list_get_by_index(&list, index, (void *) &data);

◆ list_init()

void list_init ( list_t list,
size_t  dataSize 
)

Description:

This function is used to intialize a linked list structure.

Parameters
listLinked list to be initialized.
dataSizeSize of the data of the nodes.
Returns
None.

Example:

list_t* list;
list_init(&list, sizeof(uint32_t));

◆ list_pop()

uint8_t list_pop ( list_t list,
void *  data 
)

Description:

This function is used to get the node at the end of the list.

Parameters
listLinked list.
dataPointer to the variable to which will be copied the value of the node at the end of the list.
Returns
1 if there are no elements, 0 otherwise.

Example:

uint8_t error = list_pop(&list, (void *) &data);

◆ list_pop_front()

uint8_t list_pop_front ( list_t list,
void *  data 
)

Description:

This function is used to get the node at the front of the list.

Parameters
listLinked list.
dataPointer to the variable to which will be copied the value of the node at the front of the list.
Returns
1 if there are no elements, 0 otherwise.

Example:

uint8_t error = list_pop_front(&list, (void *) &data);

◆ list_print()

void list_print ( list_t list,
void(*)(const void *data)  printFn 
)

Description:

This function is used to print the values of the list.

Parameters
listLinked list.
printFnPointer to the function used to print the elements.
Returns
None.

Example:

list_print(&list, printInt);

◆ list_push()

void list_push ( list_t list,
const void *  data 
)

Description:

This function is used to add a node to the end of the list.

Parameters
listLinked list.
dataPointer to the variable which value will be inserted at the end of the list.
Returns
None.

Example:

list_push(&list, (void *) &data);

◆ list_push_front()

void list_push_front ( list_t list,
const void *  data 
)

Description:

This function is used to add a node to the front of the list.

Parameters
listLinked list.
dataPointer to the variable which value will be inserted at the front of the list.
Returns
None.

Example:

list_push_front(&list, (void *) &data);

◆ list_size()

uint8_t list_size ( list_t list)

Description:

This function is used to get the number of elements in the list.

Parameters
listLinked list.
Returns
Number of elements in the list.

Example:

uint8_t listSize = list_size(&list);