git clone --recurse-submodules https://github.com/mcscholtz/cll.git
cd cll
cmake .
make
ctest
#include "ll.h"
struct ll * list = ll_new(DOUBLE); //Create a doubly linked list
int somedata = 1;
struct ln * node = ll_new_node(&somedata, sizeof(somedata)); //internally copy data from somedata
...
//Do stuff with the node and list, see supported opperations below
...
ll_delete_node(node);
ll_delete(list); //This will also free all items in the list if there are any left
Both the singly and doubly lists support the following oppperations:
list->push_front(list, node);
struct ln * node2 = list->pop_front(list);
list->push_back(list, node);
struct ln * node2 = list->pop_back(list);
list->push_behind(list, behind, node);
struct ln * node2 = list->pop_behind(list, node);
list->push_at(list, 1, node);
struct ln * node2 = list->pop_at(list, 1);
void add5(void * element)
{
*(int *)element += 5;
}
...
list->foreach(list,add5); //adds 5 to each element in the list
int * a = list->front(list);
*a = 123;
int * b = list->at(list, 0); //At index 0 is the same as front
assert(123 == *b);
...
For more examples look at the tests
- Add concat function
- Add split function
- Add sort function