LICK
 All Data Structures Files Functions Variables Enumerations Enumerator
Data Structures | Typedefs | Functions
llist.h File Reference

A linked list library. More...

#include <stdlib.h>
Include dependency graph for llist.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  node_t
 A linked list node. More...
 

Typedefs

typedef struct node_t node_t
 
typedef void(* free_list_item_f )(void *)
 

Functions

node_tnew_node (void *val, node_t *next)
 create a new node, and add it to the start of a list More...
 
size_t list_length (node_t *lst)
 find the length of a linked list More...
 
node_tlist_reverse (node_t *lst)
 reverse a list More...
 
node_tlist_sort (node_t *lst, int(*compare)(const void *a, const void *b))
 sort a list More...
 
void free_list (node_t *n, free_list_item_f free_fn)
 free a list, freeing all elements along the way More...
 

Detailed Description

A linked list library.

Function Documentation

void free_list ( node_t n,
free_list_item_f  free_fn 
)

free a list, freeing all elements along the way

Parameters
nthe list to free
free_fna 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
lstthe list to count
Returns
the length of the list
node_t* list_reverse ( node_t lst)

reverse a list

Parameters
lstthe 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
lstthe list to sort. This pointer passed is not valid after the function
comparethe comparison function
Returns
the sorted list
node_t* new_node ( void *  val,
node_t next 
)

create a new node, and add it to the start of a list

Parameters
valthe value of the node
nextthe list to add it to
Returns
the new linked list