#include "stack4.h" #include #include typedef struct list *list; struct list { void *element; list next; }; list cons(void *element, list l) { list temp = malloc(sizeof(struct list)); temp -> element = element; temp -> next = l; return temp; } struct stack { list elements; }; stack stack_create(void) { stack temp = malloc(sizeof(struct stack)); temp -> elements = NULL; return temp; } void stack_push(stack s, void *element) { s -> elements = cons(element, s -> elements); } int stack_empty(stack s) { return s -> elements == NULL; } void stack_pop(stack s) { list temp = s -> elements; assert(!stack_empty(s)); s -> elements = temp -> next; free(temp); } void * stack_top(stack s) { assert(!stack_empty(s)); return s -> elements -> element; }