A linked list is made up of elements where the first element must be a pointer. This pointer is used by the linked list library to form lists of the elements.
Lists are declared with the LIST() macro. The declaration specifies the name of the list that later is used with all list functions.
Example:
Lists can be manipulated by inserting or removing elements from either sides of the list (list_push(), list_add(), list_pop(), list_chop()). A specified element can also be removed from inside a list with list_remove(). The head and tail of a list can be extracted using list_head() and list_tail(), respecitively.
Files | |
| file | list.h |
| Linked list manipulation routines. | |
| file | list.c |
| Linked list library implementation. | |
Defines | |
| #define | LIST(name) |
| Declare a linked list. | |
Typedefs | |
| typedef void ** | list_t |
| The linked list type. | |
Functions | |
| void | list_init (list_t list) |
| Initialize a list. | |
| void * | list_head (list_t list) |
| Get a pointer to the first element of a list. | |
| void * | list_tail (list_t list) |
| Get the tail of a list. | |
| void * | list_pop (list_t list) |
| Remove the first object on a list. | |
| void | list_push (list_t list, void *item) |
| Add an item to the start of the list. | |
| void * | list_chop (list_t list) |
| Remove the last object on the list. | |
| void | list_add (list_t list, void *item) |
| Add an item at the end of a list. | |
| void | list_remove (list_t list, void *item) |
| Remove a specific element from a list. | |
| void | list_copy (list_t dest, list_t src) |
| Duplicate a list. | |
| int | list_length (list_t list) |
| Get the length of a list. | |
|
|
Value: static void *LIST_CONCAT(name,_list) = NULL; \ static list_t name = (list_t)&LIST_CONCAT(name,_list)
This macro declares a linked list with the specified Example
|
|
||||||||||||
|
Add an item at the end of a list. This function adds an item to the end of the list.
|
|
|
Remove the last object on the list. This function removes the last object on the list and returns it.
|
|
||||||||||||
|
Duplicate a list. This function duplicates a list by copying the list reference, but not the elements.
|
|
|
Get a pointer to the first element of a list. This function returns a pointer to the first element of the list. The element will not be removed from the list.
|
|
|
Initialize a list. This function initalizes a list. The list will be empty after this function has been called.
|
|
|
Get the length of a list. This function counts the number of elements on a specified list.
|
|
|
Remove the first object on a list. This function removes the first object on the list and returns it.
|
|
||||||||||||
|
Remove a specific element from a list. This function removes a specified element from the list.
|
|
|
Get the tail of a list. This function returns a pointer to the elements following the first element of a list. No elements are removed by this function.
|
1.3.6