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.


Variable Index

 o CAPACITY
Default maximum capacity of the stack.

Constructor Index

 o ArrayStack()
This constructor initializes the stack with the default capacity specified by the CAPACITY constant.
 o ArrayStack(int)
This constructor initializes the stack with the capacity specified by the user.

Method Index

 o isEmpty()
This function returns true if and only if the stack is empty
 o pop()
Remove the top element on the stack, moving all other elements up.
 o push(Object)
Put an element onto the top of the stack, and move all previously inserted elements down.
 o size()
Return the size of the stack, that is the number of elements it has.
 o top()
Look at the top element on the stack, without removing it or otherwise affecting the stack.

Variables

 o CAPACITY
 public static final int CAPACITY
Default maximum capacity of the stack.

Constructors

 o ArrayStack
 public ArrayStack()
This constructor initializes the stack with the default capacity specified by the CAPACITY constant.

 o ArrayStack
 public ArrayStack(int cap)
This constructor initializes the stack with the capacity specified by the user.

Parameters:
cap - Capacity of the stack

Methods

 o 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
 o 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
 o push
 public void push(Object obj)
Put an element onto the top of the stack, and move all previously inserted elements down.

 o 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
 o 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