public class ArrayStack<E> extends java.lang.Object implements BoundedStack<E>
Constructor and Description |
---|
ArrayStack(int maxSize)
Creates an ArrayList whose size and capacity are both equal
to the input maxSize, and whose entries are all null,
if this is a positive int - throwing an
IllegalArgumentException if the input maxSize is negative,
instead.
|
Modifier and Type | Method and Description |
---|---|
int |
capacity()
Reports the capacity of this bounded stack.
|
boolean |
isEmpty()
Reports whether the stack is currently empty without changing it.
|
E |
peek()
Reports the top element of the stack without changing it.
|
E |
pop()
Removes an element from the top of the stack and reports it.
|
void |
push(E x)
Pushes a new entry onto the stack.
|
public ArrayStack(int maxSize)
maxSize
- the capacity of the BoundedStack to be createdpublic void push(E x) throws StackFullException
BoundedStack
push
in interface BoundedStack<E>
x
- the object to be pushed onto the stackStackFullException
- if the Stack is already full
public E peek()
BoundedStack
peek
in interface BoundedStack<E>
public E pop()
BoundedStack
pop
in interface BoundedStack<E>
public boolean isEmpty()
BoundedStack
isEmpty
in interface BoundedStack<E>
public int capacity()
BoundedStack
capacity
in interface BoundedStack<E>