#include #include #include #include "Stack.h" struct node { int item; struct node *next; }; struct stack { struct node *top; }; static struct node *newNode(int item) { struct node *n = malloc(sizeof(struct node)); n->item = item; n->next = NULL; return n; } Stack StackNew(void) { Stack s = malloc(sizeof(struct stack)); s->top = NULL; return s; } void StackFree(Stack s) { if (s == NULL) { return; } struct node *curr = s->top; while (curr != NULL) { struct node *temp = curr; curr = curr->next; free(temp); } free(s); } void StackPush(Stack s, int item) { struct node *n = newNode(item); n->next = s->top; s->top = n; } int StackPop(Stack s) { struct node *temp = s->top; int item = temp->item; s->top = temp->next; free(temp); return item; }