osurs  0.0.1
Functions
linkedlist.c File Reference

Linkedlist data structure. More...

#include "osurs/ds/linkedlist.h"
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for linkedlist.c:

Functions

void linked_list_init (LinkedList *list)
 Initialize a LinkedList structure. More...
 
LinkedListlinked_list_create ()
 Create a new LinkedList structure. More...
 
void linked_list_add_first (LinkedList *list, void *data)
 Add an element to the beginning of a LinkedList. More...
 
void linked_list_add_last (LinkedList *list, void *data)
 Add an element to the end of a LinkedList. More...
 
void * linked_list_remove_first (LinkedList *list)
 Remove the first element from a LinkedList. More...
 
void * linked_list_remove_last (LinkedList *list)
 Remove the last element from a LinkedList. More...
 
void * linked_list_get_first (LinkedList *list)
 Get the first element of a LinkedList. More...
 
void * linked_list_get_last (LinkedList *list)
 Get the last element of a LinkedList. More...
 
void linked_list_clear (LinkedList *list)
 Clear all elements from a LinkedList. More...
 
void linked_list_free (LinkedList *list)
 Free a LinkedList structure. More...
 

Detailed Description

Linkedlist data structure.

Date
: 2022-12-20
Author
: Merlin Unterfinger

Function Documentation

◆ linked_list_add_first()

void linked_list_add_first ( LinkedList list,
void *  data 
)

Add an element to the beginning of a LinkedList.

This function adds an element to the beginning of a LinkedList.

Parameters
listThe LinkedList to which the element will be added.
dataThe element to be added to the list.

◆ linked_list_add_last()

void linked_list_add_last ( LinkedList list,
void *  data 
)

Add an element to the end of a LinkedList.

This function adds an element to the end of a LinkedList.

Parameters
listThe LinkedList to which the element will be added.
dataThe element to be added to the list.

◆ linked_list_clear()

void linked_list_clear ( LinkedList list)

Clear all elements from a LinkedList.

This function removes all elements from a LinkedList, but does not free the list structure itself.

Parameters
listThe LinkedList to be cleared.

◆ linked_list_create()

LinkedList* linked_list_create ( )

Create a new LinkedList structure.

This function creates a new LinkedList structure and returns a pointer to it. The new structure is initialized with its head and tail pointers set to NULL and its size set to 0.

Returns
A pointer to the new LinkedList structure.

◆ linked_list_free()

void linked_list_free ( LinkedList list)

Free a LinkedList structure.

This function frees a LinkedList structure, including all nodes and their data.

Parameters
listThe LinkedList structure to be freed.

◆ linked_list_get_first()

void* linked_list_get_first ( LinkedList list)

Get the first element of a LinkedList.

This function returns a pointer to the first element of a LinkedList, without removing it from the list. If the list is empty, the function returns NULL.

Parameters
listThe LinkedList from which the first element will be returned.
Returns
The first element of the list, or NULL if the list is empty.

◆ linked_list_get_last()

void* linked_list_get_last ( LinkedList list)

Get the last element of a LinkedList.

This function returns a pointer to the last element of a LinkedList, without removing it from the list. If the list is empty, the function returns NULL.

Parameters
listThe LinkedList from which the last element will be returned.
Returns
The last element of the list, or NULL if the list is empty.

◆ linked_list_init()

void linked_list_init ( LinkedList list)

Initialize a LinkedList structure.

This function initializes a LinkedList structure by setting its head and tail pointers to NULL and its size to 0.

Parameters
listThe LinkedList structure to be initialized.

◆ linked_list_remove_first()

void* linked_list_remove_first ( LinkedList list)

Remove the first element from a LinkedList.

This function removes the first element from a LinkedList and returns a pointer to it. If the list is empty, the function returns NULL.

Parameters
listThe LinkedList from which the element will be removed.
Returns
The first element of the list, or NULL if the list is empty.

◆ linked_list_remove_last()

void* linked_list_remove_last ( LinkedList list)

Remove the last element from a LinkedList.

This function removes the last element from a LinkedList and returns a pointer to it. If the list is empty, the function returns NULL.

Parameters
listThe LinkedList from which the element will be removed.
Returns
The last element of the list, or NULL if the list is empty.