package examples.stack2; import examples.stack2.Stack; import resources.Element; /** * Author: W. M. Farmer
* Revised: February 21, 2007
*
* Description: A definitional extension of the Stack class. * * @author W. M. Farmer */ public class StackPlus extends Stack { public StackPlus() { super(); } /** * Mutator that changes the top element of the stack. * * @param e the new top Element */ public void setTop(Element e) throws EmptyStackException { pop(); push(e); } /** * Mutator that empties the stack. */ public void reset() { try { while (height() != 0) { pop(); } } catch (EmptyStackException x) { // EmptyStackException should not occur. System.out.println(x.toString()); } } /** * Predicate that checks if the stack is empty. * * @return true iff the stack is empty */ public boolean isEmpty() { return height() == 0; } }