Browse Source Download (without any required ccan dependencies)
lqueue
Simple, singly-linked-list queue implementation
David Gibson <david@gibson.dropbear.id.au>
This code provides a simple implementation of the Queue abstract data type in terms of a singly linked (circular) list.
#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(argq);
for (i = 0; i < argc; i++) {
a = malloc(sizeof(*a));
a->arg = argv[i];
lqueue_enqueue(&argq, a, ql);
}
printf("Command line arguments in order:\n");
while (!lqueue_empty(&argq)) {
a = lqueue_dequeue(&argq, struct arg, ql);
printf("Argument: %s\n", a->arg);
free(a);
}
return 0;
}
BSD-MIT