Giter Club home page Giter Club logo

cll's Introduction

Build Status

Linked Lists in C

Build

git clone --recurse-submodules https://github.com/mcscholtz/cll.git
cd cll
cmake .
make
ctest

Use in your Code

#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

Supported opperations

Both the singly and doubly lists support the following oppperations:

push_front / pop_front

list->push_front(list, node);
struct ln * node2 = list->pop_front(list);

push_back / pop_back

list->push_back(list, node);
struct ln * node2 = list->pop_back(list);

push_behind / pop_behind (Push or pop the node behind the given node)

list->push_behind(list, behind, node);
struct ln * node2 = list->pop_behind(list, node);

push_at / pop_at (Push or pop the node at the given index)

list->push_at(list, 1, node);
struct ln * node2 = list->pop_at(list, 1);

foreach (Apply function to each element in the list function signature: void func(void * element)

void add5(void * element)
{
    *(int *)element += 5;
}
...
list->foreach(list,add5); //adds 5 to each element in the list

front / back / at (Directly return the pointer to the data of the requested node)

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

TODO

  • Add concat function
  • Add split function
  • Add sort function

cll's People

Contributors

mcscholtz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.