/* * 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 exercises.myContainers; import java.util.Arrays; /** * * @author Lefteris Moussiades */ public class StackOfStrings { private String[] store; private int top; public static int incStep=10; public StackOfStrings() { store = new String[10]; top = -1; } public boolean isEmpty() { return top == -1; } private void increase() { String[] lStore = Arrays.copyOfRange (store, 0, store.length + incStep); store = lStore; } public void push(String data) { if (top >= store.length - 1) { increase(); } store[++top] = data; } public String pop() { return store[top--]; } public static void main(String[] args) { StackOfStrings.incStep=100; StackOfStrings sS=new StackOfStrings(); for (int i=1; i<32; i++) sS.push(Integer.toString(i)); while (!sS.isEmpty()) System.out.print(sS.pop()+" "); } }