// Stack - Array based implementation.
// Creating a stack of integers.
#include<stdio.h>

#define MAX_SIZE 5

int A[MAX_SIZE]; // integer array to store the stack
int top = -1;  // variable to mark top of stack in array

// Push operation to insert an element on top of stack.
void Push(int x)
{
  if(top == MAX_SIZE-1) { // overflow case.
		printf(" stack overflow\n");
		return;
	}
	A[++top] = x;
}

// Pop operation to remove an element from top of stack.
void Pop()
{
	if(top == -1) { // If stack is empty, pop should throw error.
		printf("Error: No element to pop\n");
		return;
	}
	top--;
}


// This will print all the elements in the stack at any stage.
void display() {
	int i;
	printf("Stack: ");
	for(i = 0;i<=top;i++)
		printf("%d ",A[i]);
	printf("\n");
}

int main() {
  // Code to test the implementation.
  // calling display() after each push or pop to see the state of stack.
Push(10);
push(20);
push(30);
push(40);
push(50);
pop();
display();
}
