public class ArrayStack<E> extends Object implements Stack<E>
Modifier and Type | Field and Description |
---|---|
static int |
CAPACITY
Default array capacity.
|
Constructor and Description |
---|
ArrayStack()
Constructs an empty stack using the default array capacity.
|
ArrayStack(int capacity)
Constructs and empty stack with the given array capacity.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isEmpty()
Tests whether the stack is empty.
|
static void |
main(String[] args)
Demonstrates sample usage of a stack.
|
E |
pop()
Removes and returns the top element from the stack.
|
void |
push(E e)
Inserts an element at the top of the stack.
|
int |
size()
Returns the number of elements in the stack.
|
E |
top()
Returns, but does not remove, the element at the top of the stack.
|
String |
toString()
Produces a string representation of the contents of the stack.
|
public static final int CAPACITY
public ArrayStack()
public ArrayStack(int capacity)
capacity
- length of the underlying arraypublic int size()
public boolean isEmpty()
public void push(E e) throws IllegalStateException
push
in interface Stack<E>
e
- the element to be insertedIllegalStateException
- if the array storing the elements is fullpublic E top()
public E pop()
public String toString()
public static void main(String[] args)