package com.codechef.javaapp;
import java.util.*;
class main {
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int data[] = new int[n];
for(int i = 0;i<n;i++){
data[i] = sc.nextInt();
}
new StackUsingArrays(data,n);
}
}
class StackUsingArrays {
public int size;
protected int data[];
protected int top;
public StackUsingArrays(int[] data, int n) throws Exception {
this.data = data;
if(n<1){
throw new Exception(“invalid capacity entered”);
}
this.data = new int[n];
this.top = -1;
}
public StackUsingArrays() {
}
public int size(){
return this.top+1; // this will return the size of the current stack
}
public boolean isEmpty(){
return this.size() ==0;
}
public void push(int element) throws Exception{
if(this.top == this.size()){
throw new Exception("Stack is full");
}
this.top++;
this.data[this.top] = element;
}
public int pop() throws Exception{
if(this.size() == 0){
throw new Exception("Stack is empty");
}
int element = this.data[this.top];
this.data[this.top] = 0;
this.top--;
return element;
}
public int top() throws Exception{
if(this.size()==0){
throw new Exception("Stack is Empty");
}
int element = this.data[this.top];
return element;
}
public void display() throws Exception {
for(int i = this.top();i>=0;i--){
System.out.print(this.data[i]+", ");
}
System.out.println(" End ");
}
}
class DequeueCoefficient{
StackUsingArrays primary;
StackUsingArrays secondary;
public DequeueCoefficient() throws Exception {
this.primary = new StackUsingArrays();
this.secondary = new StackUsingArrays();
}
public void enqueue(int data) throws Exception{
while(primary.size != 0){
secondary.push(primary.pop());
}
primary.push(data);
while(secondary.size != 0){
primary.push(secondary.pop());
}
}
public int dequeue() throws Exception{
return this.primary.pop();
}
public int front() throws Exception{
return this.primary.top();
}
public void display() throws Exception{
this.primary.display();
}
}