|
datastructures | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.datastructures.ArrayStack
Implementation of the Stack interface using a fixed-length array. An exception is thrown if a push operation is attempted when the size of the stack is equal to the length of the array.
FullStackException| Field Summary | |
protected int |
capacity
Length of the array used to implement the stack. |
static int |
CAPACITY
Default length of the array used to implement the stack. |
protected Object[] |
S
Array used to implement the stack. |
protected int |
top
Index of the top element of the stack in the array. |
| Constructor Summary | |
ArrayStack()
Initialize the stack to use an array of default length CAPACITY. |
|
ArrayStack(int cap)
Initialize the stack to use an array of given length. |
|
| Method Summary | |
boolean |
isEmpty()
O(1) time. |
Object |
pop()
O(1) time. |
void |
push(Object obj)
O(1) time. |
int |
size()
O(1) time. |
Object |
top()
O(1) time. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int CAPACITY
protected int capacity
protected Object[] S
protected int top
| Constructor Detail |
public ArrayStack()
public ArrayStack(int cap)
cap - length of the array.| Method Detail |
public int size()
size in interface Stackpublic boolean isEmpty()
isEmpty in interface Stack
public void push(Object obj)
throws FullStackException
push in interface Stackobj - element to be inserted.
FullStackException - if the array is full.
public Object top()
throws EmptyStackException
top in interface StackEmptyStackException - if the stack is empty.
public Object pop()
throws EmptyStackException
pop in interface StackEmptyStackException - if the stack is empty.
|
datastructures | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||