//<PLAINTEXT>
import java.util.*;

/**
 * LStack.java<br>
 * Illustrates the implementation of a stack based on a linked list.<p>
 *
 * Created: Mon Mar 24 10:37:56 2003
 *
 * @author <a href="mailto:shapiro@cse.buffalo.edu">Stuart C. Shapiro</a>
 */

public class LStack {
    private LinkdList stack;

    /**
     * Creates a new <code>LStack</code> instance.
     *
     */
    public LStack (){
	stack = new LinkdList();
    }

    /**
     * Determines if this LStack is empty.
     *
     * @return true if this LStack has no elements in it;
     * otherwise returns false.
     */
    public boolean empty () {
	return stack.isEmpty();
    }

    /**
     * Adds a new Object to the top of this LStack.
     *
     * @param obj the <code>Object</code> to be pushed onto this LStack.
     */
    public void push (Object obj) {
	stack = new LinkdList(obj, stack);
    }

    /**
     * Returns the Object on the top of this LStack.
     *
     * @return the <code>Object</code> on the top of this LStack.
     * @exception NoSuchElementException if this LStack is empty.
     */
    public Object top () throws NoSuchElementException {
	return stack.getFirst();
    }

    /**
     * Removes and returns the Object on the top of this LStack.
     *
     * @return the <code>Object</code> that was on the top of this
     * LStack, after removing it.
     * @exception NoSuchElementException if this LStack is empty.
     */
    public Object pop () throws NoSuchElementException {
	Object obj = stack.getFirst();
	stack = stack.getRest();
	return obj;
    }

    /**
     * Returns a String representation of this LStack,
     * with the top Object shown at the left.
     *
     * @return a <code>String</code> representation of this LStack.
     */
    public String toString () {
	return stack.toString();
    }
    
}// LStack
