Interface StackGeneric_Interface<E>
- Type Parameters:
E- Type of elements stored in the stack.
- All Known Implementing Classes:
DLinked_StackGeneric
public interface StackGeneric_Interface<E>
A generic stack.
- Author:
- Kevin Lillis
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all elements from this stack.booleanisEmpty()Returns true if this stack is empty, returns false otherwise.peek()Returns but does not remove the element at the top of this stack.pop()Removes and returns the element at the top of this stack.voidAdds the given element to the top of the stack.intsize()Returns the number of elements in this stack.toString()Returns a string containing each element in this list, separated by commas, enclosed in square brackets.
-
Method Details
-
push
Adds the given element to the top of the stack.- Parameters:
element- element to be added to the top of this stack
-
pop
Removes and returns the element at the top of this stack.- Returns:
- the element at the top of this stack
- Throws:
EmptyStackException- if this stack is empty.
-
peek
Returns but does not remove the element at the top of this stack.- Returns:
- the element at the top of this stack.
- Throws:
EmptyStackException- if this stack is empty.
-
size
int size()Returns the number of elements in this stack.- Returns:
- number of elements in this stack
-
isEmpty
boolean isEmpty()Returns true if this stack is empty, returns false otherwise.- Returns:
- true if this stack is empty, returns false otherwise
-
clear
void clear()Removes all elements from this stack. If the stack is empty, nothing is done. -
toString
-