StackInterface.java (1432B)
1 package collections; 2 3 public interface StackInterface<T> { 4 public boolean isEmpty(); 5 // Determines whether the stack is empty. 6 // Precondition: None. 7 // Postcondition: Returns true if the stack is empty; 8 // otherwise returns false. 9 10 public void popAll(); 11 // Removes all the items from the stack. 12 // Precondition: None. 13 // PostCondition: Stack is empty. 14 15 public void push(T newItem) throws StackException; 16 // Adds an item to the top of a stack. 17 // Precondition: newItem is the item to be added. 18 // Postcondition: If insertion is successful, newItem 19 // is on the top of the stack. 20 // Exception: Some implementations may throw 21 // StackException when newItem cannot be placed on 22 // the stack. 23 24 public T pop() throws StackException; 25 // Removes the top of a stack. 26 // Precondition: None. 27 // Postcondition: If the stack is not empty, the item 28 // that was added most recently is removed from the 29 // stack. 30 // Exception: Throws StackException if the stack is 31 // empty. 32 33 public T peek() throws StackException; 34 // Retrieves the top of a stack. 35 // Precondition: None. 36 // Postcondition: If the stack is not empty, the item 37 // that was added most recently is returned. The 38 // stack is unchanged. 39 // Exception: Throws StackException if the stack is 40 // empty. 41 public String toString(); 42 } // end StackInterface 43