UNB/ CS/ David Bremner/ teaching/ old/ cs1083/ java/ LinkedStack.java
import java.util.Scanner;
import java.util.EmptyStackException;
public class LinkedStack<T> {

    private Node<T> topNode=null;
    public void push(T obj){
        Node<T> newNode=new Node<T>(obj);
        newNode.setNext(topNode);
        topNode=newNode;
    }

    public T pop(){
        if (topNode==null)
            throw new EmptyStackException();

        T rval=topNode.getData();
        topNode=topNode.getNext();

        return rval;
    }

    public boolean isEmpty(){
        return (topNode==null);
    }

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