public class IntArrayStack
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
IntArrayStack.UnderflowException |
Modifier and Type | Field and Description |
---|---|
private int[] |
array |
private static int |
INITIAL_CAPACITY |
private int |
top |
Constructor and Description |
---|
IntArrayStack() |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Empties the stack.
|
private void |
expandCapacity() |
void |
getElements(int[] destArray,
int destStartIndex)
Copies all elements currently on the stack into the given array.
|
boolean |
isEmpty()
Tests if the stack is empty.
|
int |
peek()
Returns the item at the top of the stack without removing it.
|
int |
pop()
Removes the most recently inserted item from the stack.
|
void |
push(int x)
Pushes a new item onto the stack.
|
int |
size()
Returns the number of element currently on the stack.
|
int[] |
toArray() |
private static final int INITIAL_CAPACITY
private int[] array
private int top
public boolean isEmpty()
public int size()
public void getElements(int[] destArray, int destStartIndex)
destArray
- the arraydestStartIndex
- the index to start copying intopublic int[] toArray()
public void clear()
public int peek()
IntArrayStack.UnderflowException
- if the stack is empty.public int pop()
IntArrayStack.UnderflowException
- if the stack is empty.public void push(int x)
x
- the item to add.private void expandCapacity()