Browse Source Download (without any required ccan dependencies)

Module:

lqueue

Summary:

Simple, singly-linked-list queue implementation

Author:

David Gibson <[email protected]>

Dependencies:

Description:

This code provides a simple implementation of the Queue abstract data type in terms of a singly linked (circular) list.

Example:

#include <ccan/lqueue/lqueue.h>

struct arg {
        const char *arg;
        struct lqueue_link ql;
};

int main(int argc, char *argv[])
{
        int i;
        struct arg *a;
        LQUEUE(struct arg, ql) argq = LQUEUE_INIT;

        for (i = 0; i < argc; i++) {
                a = malloc(sizeof(*a));
                a->arg = argv[i];
                lqueue_enqueue(&argq, a);
        }

        printf("Command line arguments in order:\n");

        while (!lqueue_empty(&argq)) {
                a = lqueue_dequeue(&argq);
                printf("Argument: %s\n", a->arg);
                free(a);
        }

        return 0;
}

License:

BSD-MIT