UNB/ CS/ David Bremner/ teaching/ old/ cs1083/ java/ ArrayStack.java
import java.util.Scanner;

public class ArrayStack {
    private String[] stack;
    int top;
    public ArrayStack(int size) {
        stack = new String[size];
        top = -1;
    }

    public String getStringop() {
        return stack[top];
    }

    public boolean isEmpty() {
        return (top < 0);
    }

    public void push(String element) {
        top++;
        if (top >= stack.length)
            throw new RuntimeException("Full stack");

        stack[top]=element;
    }

    public String pop() {
        if (isEmpty())
            throw new RuntimeException("empty stack");
        String retval = stack[top];
        top--;
        return retval;
    }

    public static void main(String[] args){
        String sentence = "Shooby doo wop she bop" ;
        Scanner words =new Scanner(sentence);
        ArrayStack stack=
            new ArrayStack(10);
        while(words.hasNext()){
            stack.push(words.next());
        }
        while (!stack.isEmpty()){
            System.out.print(stack.pop()+" ");
        }
    }
}