package com.stackfundamentals;

public class Stack {
    int stck[] = new int[10];
    int tos;

    //Initialise the Top-of-Stack via a Constructor
    public Stack() {
        tos = -1;
    }

    //Push an item onto the Stack
    public void push(int item) {
        if(tos == 9) {
            System.out.println("Stack is full!!");
        }
        else {
            stck[++tos] = item;
        }
    }
    //Pop an item from the Stack
    public int pop() {
        if(tos < 0) {
            System.out.println("Stack Underflow!!");
            return 0;
        }
        else {
            return stck[tos--];
        }
    }
}

public class TestStack {
    public static void main(String[] args) {
        Stack mystack1 = new Stack();
        Stack mystack2 = new Stack();

        //Push some numbers onto the Stack
        for(int i = 0; i < 10; i++) {
            mystack1.push(i);
        }
        for(int i = 10; i < 20; i++) {
            mystack2.push(i);
        }

        //Pop some number off the Stack
        for(int i = 0; i < 10; i++) {
            System.out.println(mystack1.pop());
        }
        for(int i = 10; i < 20; i++) {
            System.out.println(mystack2.pop());
        }
    }
 }