osurs
0.0.1
|
Linkedlist data structure. More...
#include <stddef.h>
Go to the source code of this file.
Data Structures | |
struct | ListNode |
Linked list node. More... | |
struct | LinkedList |
Linked list. More... | |
Typedefs | |
typedef struct ListNode | ListNode |
Linked list node. More... | |
typedef struct LinkedList | LinkedList |
Linked list. More... | |
Functions | |
void | linked_list_init (LinkedList *list) |
Initialize a LinkedList structure. More... | |
LinkedList * | linked_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... | |
Linkedlist data structure.
This file defines a LinkedList data structure, which is an abstract data type (ADT) that implements a doubly linked list. Each node of the list contains a value and two pointers: one pointing to the previous node in the list and one pointing to the next node in the list. This allows for efficient insertion and deletion of elements at the ends of the list, as well as the ability to easily traverse the list in both directions. The head of the list points to the first node, and the tail of the list points to the last node. If the list is empty, both the head and the tail will be null.
typedef struct LinkedList LinkedList |
Linked list.
This structure represents a LinkedList data structure. It consists of pointers to the head and tail of the list (the first and last nodes in the list), as well as an integer size representing the number of elements in the list.
Linked list node.
This structure represents a node in a LinkedList data structure. It consists of pointers to the previous and next nodes in the list, as well as a void pointer to the node's data.
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.
list | The LinkedList to which the element will be added. |
data | The element to be added to the list. |
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.
list | The LinkedList to which the element will be added. |
data | The element to be added to the list. |
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.
list | The LinkedList to be cleared. |
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.
void linked_list_free | ( | LinkedList * | list | ) |
Free a LinkedList structure.
This function frees a LinkedList structure, including all nodes and their data.
list | The LinkedList structure to be freed. |
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.
list | The LinkedList from which the first element will be returned. |
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.
list | The LinkedList from which the last element will be returned. |
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.
list | The LinkedList structure to be initialized. |
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.
list | The LinkedList from which the element will be removed. |
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.
list | The LinkedList from which the element will be removed. |