#include "stack.h" void stack_add(void* _data, struct stack** _stackpointer) { struct stack* newsp = malloc(sizeof(*newsp)); newsp->data = _data; newsp->next = *_stackpointer; *_stackpointer = newsp; } void* stack_get(struct stack** _stackpointer) { void* return_data; struct stack* oldsp; //Old stackpointer if(!*_stackpointer) return NULL; return_data = (*_stackpointer)->data; oldsp = *_stackpointer; *_stackpointer = (*_stackpointer)->next; free(oldsp); return return_data; } void stack_init(struct stack** _stackpointer) { stack_flush(_stackpointer); *_stackpointer = NULL; } void stack_flush(struct stack** _stackpointer) { while(*_stackpointer) stack_get(_stackpointer); }