Package examples
Interface Stack<T>
public interface Stack<T>
-
Method Summary
Modifier and Type Method Description booleanisEmpty()Test whether any elements are currently waiting on the stack.Tpeek()Returns (but does not remove) the element at the top of the stack.Tpop()Removes the element from the top of the stack and returns it.booleanpush(T e)Add an element to the top of the stack.intsize()Returns the number of elements currently waiting on the stack.
-
Method Details
-
isEmpty
boolean isEmpty()Test whether any elements are currently waiting on the stack.- Returns:
- true if the stack is empty; false otherwise.
-
size
int size()Returns the number of elements currently waiting on the stack.- Returns:
- how many items are in this collection
-
push
Add an element to the top of the stack.- Parameters:
e- the element to add to this collection.- Returns:
- true if the stack is not full and the element was succesfully added; false otherwise.
-
pop
T pop()Removes the element from the top of the stack and returns it.- Returns:
- null if the stack is empty; otherwise, the most recently pushed element.
-
peek
T peek()Returns (but does not remove) the element at the top of the stack.- Returns:
- null if the stack is empty; otherwise, the most recently pushed element.
-