Browse Source Download (without any required ccan dependencies)
lstack
Simple, singly-linked-list stack implementation
David Gibson <david@gibson.dropbear.id.au>
This code provides a simple implementation of the Stack abstract data type in terms of a singly linked list.
#include <ccan/lstack/lstack.h>
struct arg {
const char *arg;
struct lstack_link sl;
};
int main(int argc, char *argv[])
{
int i;
struct arg *a;
LSTACK(argstack);
for (i = 0; i < argc; i++) {
a = malloc(sizeof(*a));
a->arg = argv[i];
lstack_push(&argstack, a, sl);
}
printf("Command line arguments in reverse:\n");
while (!lstack_empty(&argstack)) {
a = lstack_pop(&argstack, struct arg, sl);
printf("Argument: %s\n", a->arg);
free(a);
}
return 0;
}
BSD-MIT