#include
struct node {
int *element;
struct node *next;
};
struct stack {
struct node *head;
};
void stack_init(struct stack *s) {
s->head = NULL;
}
void stack_push(struct stack *s, int *element) {
struct node *n = malloc(sizeof(struct node));
n->element = element;
n->next = s->head;
s->head = n;
}
int *stack_pop(struct stack *s) {
if(s->head == NULL)
return NULL; // stack is empty
struct node *n = s->head;
s->head = n->next;
int *result = n->element;
free(n); n = NULL;
return result;
}