Linked lists implementation.
More...
Go to the source code of this file.
|
| void | List_Append (Lz_LinkedList *const linkedList, Lz_LinkedListElement *const item) |
| | Insert an Lz_LinkedListElement as the last element of an existing Lz_LinkedList.
|
| |
| void | List_Prepend (Lz_LinkedList *const linkedList, Lz_LinkedListElement *const item) |
| | Insert an Lz_LinkedListElement as the first element of an existing Lz_LinkedList.
|
| |
| void | List_AppendList (Lz_LinkedList *const linkedListDestination, Lz_LinkedList *const linkedListToMove) |
| | Move the content of an Lz_LinkedList to the end of an existing Lz_LinkedList.
|
| |
| Lz_LinkedListElement * | List_PickFirst (Lz_LinkedList *const linkedList) |
| | Return the first element of an existing linked list.
|
| |
| Lz_LinkedListElement * | List_PointFirst (const Lz_LinkedList *const linkedList) |
| | Return a pointer to the first element of an existing linked list.
|
| |
| bool | List_IsEmpty (const Lz_LinkedList *const linkedList) |
| | Test if an Lz_LinkedList is empty.
|
| |
| void | List_InsertAfter (Lz_LinkedList *const linkedList, Lz_LinkedListElement *const listItem, Lz_LinkedListElement *const itemToInsert) |
| | Insert an element after another in an Lz_LinkedList.
|
| |
| void | List_InsertBefore (Lz_LinkedList *const linkedList, Lz_LinkedListElement *const listItem, Lz_LinkedListElement *const itemToInsert) |
| | Insert an element before another in a Lz_LinkedList.
|
| |
| Lz_LinkedListElement * | List_Remove (Lz_LinkedList *const linkedList, Lz_LinkedListElement *const itemToRemove) |
| | Remove an element from an Lz_LinkedList.
|
| |
| Lz_LinkedListElement * | List_PointElementAt (const Lz_LinkedList *const linkedList, const size_t index) |
| | Point to an indexed element in an Lz_LinkedList, starting at index 0.
|
| |
| void | List_InitLinkedList (Lz_LinkedList *const linkedList) |
| | Initialize an Lz_LinkedList.
|
| |
| void | List_InitLinkedListElement (Lz_LinkedListElement *const item) |
| | Initialize an Lz_LinkedListElement.
|
| |
Linked lists implementation.
- Copyright
- 2017-2020, Remi Andruccioli remi..nosp@m.andr.nosp@m.uccio.nosp@m.li@g.nosp@m.mail..nosp@m.com
This file describes the implementation of generic doubly linked lists.
Definition in file list.c.
◆ List_Append()
Insert an Lz_LinkedListElement as the last element of an existing Lz_LinkedList.
- Parameters
-
| linkedList | A pointer to the linked list head. |
| item | A pointer to the item to append to the list. |
Definition at line 22 of file list.c.
◆ List_Prepend()
Insert an Lz_LinkedListElement as the first element of an existing Lz_LinkedList.
- Parameters
-
| linkedList | A pointer to the linked list head. |
| item | A pointer to the item to prepend to the list. |
Definition at line 46 of file list.c.
◆ List_AppendList()
Move the content of an Lz_LinkedList to the end of an existing Lz_LinkedList.
- Parameters
-
| linkedListDestination | A pointer to the Lz_LinkedList on which to append. |
| linkedListToMove | A pointer to the Lz_LinkedList to move. After the operation, this linked list will be empty. |
Definition at line 71 of file list.c.
◆ List_PickFirst()
Return the first element of an existing linked list.
This function drops the first element of the list if it exists.
- Parameters
-
| linkedList | A pointer to the linked list head. |
- Returns
- A pointer to the first element of the list, or NULL if:
- The
linkedList is empty
- The parameter
linkedList is NULL
Definition at line 98 of file list.c.
◆ List_PointFirst()
Return a pointer to the first element of an existing linked list.
This function does not drop the first element of the list.
- Parameters
-
- Returns
- A pointer to the first element of the list, or NULL if:
- The
linkedList is empty
- The parameter
linkedList is NULL
Definition at line 129 of file list.c.
◆ List_IsEmpty()
Test if an Lz_LinkedList is empty.
- Parameters
-
- Returns
- true if:
- The
linkedList is empty
- The parameter
linkedList is NULL
- false if:
- The
linkedList contains at least 1 element
Definition at line 141 of file list.c.
◆ List_InsertAfter()
Insert an element after another in an Lz_LinkedList.
- Parameters
-
| linkedList | A pointer to the LinkedList containing the element listItem on which to insert after. |
| listItem | A pointer to an element on which to insert after, already present in the linkedList. |
| itemToInsert | A pointer to the item to insert in the list. |
- Warning
- The
listItem parameter MUST already be part of the Lz_LinkedList pointed to by parameter linkedList. No check is performed.
Definition at line 153 of file list.c.
◆ List_InsertBefore()
Insert an element before another in a Lz_LinkedList.
- Parameters
-
| linkedList | A pointer to the Lz_LinkedList containing the element listItem on which to insert before. |
| listItem | A pointer to an element on which to insert before, already present in the linkedList. |
| itemToInsert | A pointer to the item to insert in the list. |
- Warning
- The
listItem parameter MUST already be part of the Lz_LinkedList pointed to by parameter linkedList. No check is performed.
Definition at line 173 of file list.c.
◆ List_Remove()
Remove an element from an Lz_LinkedList.
- Parameters
-
| linkedList | A pointer to the Lz_LinkedList containing the element to remove. |
| itemToRemove | A pointer to the element to remove from the list. |
- Returns
- A pointer to the previous element of
itemToRemove before it is removed. This return value must be used to update an iterator when using List_RemovableForEach, in order to allow removing elements from a list while iterating on it.
- Warning
- The
itemToRemove parameter MUST already be part of the Lz_LinkedList pointed to by parameter linkedList. No check is performed.
Definition at line 197 of file list.c.
◆ List_PointElementAt()
Point to an indexed element in an Lz_LinkedList, starting at index 0.
The element will not be removed from the list.
- Warning
- The complexity of this function is O(n), as it is iterative.
- Parameters
-
| linkedList | A pointer to an Lz_LinkedList. |
| index | The index of the element to point. |
- Returns
- A pointer to the indexed Lz_LinkedListElement, or NULL if the index is out of the boundaries of the list.
Definition at line 229 of file list.c.
◆ List_InitLinkedList()
◆ List_InitLinkedListElement()
Initialize an Lz_LinkedListElement.
- Parameters
-
| item | A pointer to the Lz_LinkedListElement to initialize. |
Definition at line 266 of file list.c.