Created
September 15, 2019 18:35
-
-
Save cppio/fc49928991fe65bea0ccd5f8750e922a to your computer and use it in GitHub Desktop.
Dead simple stack implemented as a linked list in C.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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