Browse Source Download (without any required ccan dependencies)
lqueue
Simple, singly-linked-list queue implementation
David Gibson <[email protected]>
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(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;
}
BSD-MIT