| 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.datastructures.ArrayStack<E>
public class ArrayStack<E>
Implementation of the stack ADT 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. This class includes the main methods of the built-in class java.util.Stack.
FullStackException| Field Summary | |
|---|---|
static int | 
CAPACITY
Default array capacity.  | 
| Constructor Summary | |
|---|---|
ArrayStack()
Initializes the stack to use an array of default length.  | 
|
ArrayStack(int cap)
Initializes the stack to use an array of given length.  | 
|
| Method Summary | |
|---|---|
 boolean | 
isEmpty()
Testes whether the stack is empty.  | 
static void | 
main(java.lang.String[] args)
Test our program by performing a series of operations on stacks, printing the operations performed, the returned elements and the contents of the stack involved, after each operation.  | 
 E | 
pop()
Removes the top element from the stack.  | 
 void | 
push(E element)
Inserts an element at the top of the stack.  | 
 int | 
size()
Returns the number of elements in the stack.  | 
 void | 
status(java.lang.String op,
       java.lang.Object element)
Prints status information about a recent operation and the stack.  | 
 E | 
top()
Inspects the element at the top of the stack.  | 
 java.lang.String | 
toString()
Returns a string representation of the stack as a list of elements, with the top element at the end: [ ...  | 
| Methods inherited from class java.lang.Object | 
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Field Detail | 
|---|
public static final int CAPACITY
| Constructor Detail | 
|---|
public ArrayStack()
public ArrayStack(int cap)
cap - length of the array.| Method Detail | 
|---|
public int size()
size in interface Stack<E>public boolean isEmpty()
isEmpty in interface Stack<E>
public void push(E element)
          throws FullStackException
push in interface Stack<E>element - element to be inserted.
FullStackException - if the array storing the elements is full.
public E top()
      throws EmptyStackException
top in interface Stack<E>EmptyStackException - if the stack is empty.
public E pop()
      throws EmptyStackException
pop in interface Stack<E>EmptyStackException - if the stack is empty.public java.lang.String toString()
toString in class java.lang.Object
public void status(java.lang.String op,
                   java.lang.Object element)
op - operation performedelement - element returned by the operationpublic static void main(java.lang.String[] args)
  | 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||