A linked list library.
More...
#include <stdlib.h>
Go to the source code of this file.
|
typedef struct node_t | node_t |
|
typedef void(* | free_list_item_f )(void *) |
|
void free_list |
( |
node_t * |
n, |
|
|
free_list_item_f |
free_fn |
|
) |
| |
free a list, freeing all elements along the way
- Parameters
-
n | the list to free |
free_fn | a function to free all the elements of the list. For example, if the linked list contains strings allocated using malloc(), free_fn would be free(). Can be NULL to not free the elements. |
size_t list_length |
( |
node_t * |
lst | ) |
|
find the length of a linked list
- Parameters
-
- Returns
- the length of the list
reverse a list
- Parameters
-
lst | the list to reverse. This pointer passed is not valid after the function |
- Returns
- the reversed list
node_t* list_sort |
( |
node_t * |
lst, |
|
|
int(*)(const void *a, const void *b) |
compare |
|
) |
| |
sort a list
- Parameters
-
lst | the list to sort. This pointer passed is not valid after the function |
compare | the comparison function |
- Returns
- the sorted list
create a new node, and add it to the start of a list
- Parameters
-
val | the value of the node |
next | the list to add it to |
- Returns
- the new linked list