Giter Club home page Giter Club logo

doublylinkedlist's Introduction

Doubly Linked List implementation in C

A simple implementation of a doubly-linked list in C.
It has tests and is generally reliable (but not foolproof).
No standard library functions are used, so all the code is freestanding

Functions

The available functions are described in the dllist.h.

How to use

Include dllist.h and don't forget to compile dllist.c
Example:

#include "dllist/dllist.h"

typedef struct {
    dll_node_t dll_node; // It's worth specifying the node first, it makes life easier
    int some_data; // Or data ptr
} data_t;

doubly_linked_list_t list;
memset(&list, 0, sizeof(doubly_linked_list_t));
data_t* data_array_ptr = (data_t*)malloc(sizeof(data_t) * 2);
if (data_array_ptr == NULL) {
    return -1;
}
data_array_ptr[0].some_data = 1;
data_array_ptr[1].some_data = 2;

dll_insert_node_to_tail(&list, (dll_node_t*)&data_array_ptr[0]); // Or &data_array_ptr[0].dll_node
dll_insert_node_to_tail(&list, (dll_node_t*)&data_array_ptr[1]); // Or &data_array_ptr[1].dll_node

// Get first and second node data
data_t* first_node_data = (data_t*)list.head; // Or (data_t*)dll_get_nth_node(&list, 0);
data_t* second_node_data = (data_t*)list.tail; // Or (data_t*)dll_get_nth_node(&list, 1);
printf("First node data %d\n", first_node_data->some_data);
printf("Second node data %d\n", second_node_data->some_data);

free(data_array_ptr);

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.