/* Design a simple stack Emad Arasteh November 14, 2019 */ #include #include #define SIZE 10 int stack[SIZE]; int top = 0; /* insert an element at the top of the stack */ void push(int); /* remove an element from the top of the stack */ int pop(void); /* display current elements inside the stack */ void display(void); void push(int val) { if (top == SIZE) { printf("Stack is full!\n"); exit(1); } stack[top++] = val; } int pop() { if (top == 0) { printf("Stack is empty!\n"); exit(2); } return stack[--top]; } void display() { int i; printf("----\n"); for(i=top-1; i>=0; i--) { printf("|%2d|\n", stack[i]); printf("---\n"); } } int main() { printf("Push elements on the empty stack...\n"); push(57); push(37); push(19); push(5); display(); printf("Pop an element: %0d\n", pop()); display(); printf("Pop another element: %0d\n", pop()); display(); return 0; }