Skip to content

Instantly share code, notes, and snippets.

@cppio
Created September 15, 2019 18:35
Show Gist options
  • Select an option

  • Save cppio/fc49928991fe65bea0ccd5f8750e922a to your computer and use it in GitHub Desktop.

Select an option

Save cppio/fc49928991fe65bea0ccd5f8750e922a to your computer and use it in GitHub Desktop.
Dead simple stack implemented as a linked list in C.
struct stack {
struct stack* next;
void* data;
};
void push(struct stack** stack, void* data) {
struct stack* new = malloc(sizeof *new);
new->next = *stack;
new->data = data;
*stack = new;
}
void pop(struct stack** stack) {
struct stack* old = *stack;
*stack = old->next;
free(old);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment