All Packages Class Hierarchy This Package Previous Next Index
Class jdsl.simple.ref.ArrayStack
java.lang.Object
|
+----jdsl.simple.ref.ArrayStack
- public class ArrayStack
- extends Object
- implements Stack
Implementation of the Stack interface using an array. The stack can store
at most a given number of elements; if the user tries to insert more than that,
number, an exception is thrown.
- Version:
- Thu Aug 21 19:31:31 1997
- Author:
- Natasha Gelfand
-
CAPACITY
-
Default maximum capacity of the stack.
-
ArrayStack()
-
This constructor initializes the stack with the default capacity
specified by the CAPACITY constant.
-
ArrayStack(int)
-
This constructor initializes the stack with the capacity specified by
the user.
-
isEmpty()
-
This function returns true if and only if the stack is empty
-
pop()
-
Remove the top element on the stack, moving all other
elements up.
-
push(Object)
-
Put an element onto the top of the stack, and move all
previously inserted elements down.
-
size()
-
Return the size of the stack, that is the number of elements it has.
-
top()
-
Look at the top element on the stack, without removing it
or otherwise affecting the stack.
CAPACITY
public static final int CAPACITY
- Default maximum capacity of the stack.
ArrayStack
public ArrayStack()
- This constructor initializes the stack with the default capacity
specified by the CAPACITY constant.
ArrayStack
public ArrayStack(int cap)
- This constructor initializes the stack with the capacity specified by
the user.
- Parameters:
- cap - Capacity of the stack
size
public int size()
- Return the size of the stack, that is the number of elements it has.
- Returns:
- Number of elements in the stack
isEmpty
public boolean isEmpty()
- This function returns true if and only if the stack is empty
- Returns:
- true if the stack is empty, false otherwise
push
public void push(Object obj)
- Put an element onto the top of the stack, and move all
previously inserted elements down.
top
public Object top() throws StackEmptyException
- Look at the top element on the stack, without removing it
or otherwise affecting the stack.
- Returns:
- The element at the top of the stack
pop
public Object pop() throws StackEmptyException
- Remove the top element on the stack, moving all other
elements up.
- Returns:
- The top element of the stack
All Packages Class Hierarchy This Package Previous Next Index