#include #include #include"ex1_stack.h" void init_stack(struct stack * s) { s->top = NULL; }; void push(struct stack * s, int data) { struct node * tmp = (struct node *) malloc(sizeof(struct node)); if(tmp == NULL) { printf ("Remove items\n"); return; } tmp->data = data; tmp->prev = s->top; s->top = tmp; return; } int pop(struct stack * s) { struct node * top = s->top; int i = top->data; s->top = top->prev; return i; } void print_stack(const struct stack * s) { if (s->top == NULL) printf("\nEmpty Stack\n"); else { printf("\nItems in Stack : "); struct node * tmp = s->top; while(tmp!=NULL) { printf(" %d ",tmp->data); tmp = tmp->prev; } printf("\n\n"); } return; }