/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package lang; /** * * @author (C)Y.D.Zakovryashin, 07.11.2022 */ public class Stack { public final int DEFAULT_SIZE = 128; private T[] stack; private int top; public Stack(T[] stack) { // size = size < 1 ? DEFAULT_SIZE : size; this.stack = stack; top = 0; } public void push(T x) throws FullStackException { if (top == DEFAULT_SIZE) { throw new FullStackException(); } stack[top] = x; ++top; } public T pop() throws EmptyStackException { if (top < 1) { throw new EmptyStackException(); } return stack[--top]; } }