csc241.samples.Stack
Class dynamicStack

java.lang.Object
  |
  +--csc241.samples.Stack.dynamicStack
All Implemented Interfaces:
Stack

public class dynamicStack
extends java.lang.Object
implements Stack

~mohammad/public_html/classes/csc241/Stack/dynamicStack.java This version implements Stack using a linked list; and is never full. The concept here is unlike anything you have done before; it is important to understand object refernencing.
A Stack has two components:


Constructor Summary
dynamicStack()
          construct a dynamicStack
 
Method Summary
 boolean empty()
          return true if stack is empty, otherwise, return false.
topElement_ being null implies the stack is empty.
 boolean full()
          always return false.
 csc241.samples.Stack.Stack pop()
          remove an element from the top of the stack.
Simply, return restOfStack_.
 csc241.samples.Stack.Stack push(java.lang.Object x)
          add an element to the top of the stack.
 java.lang.Object top()
          return the element on top of the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

dynamicStack

public dynamicStack()
construct a dynamicStack

Method Detail

empty

public boolean empty()
return true if stack is empty, otherwise, return false.
topElement_ being null implies the stack is empty.

Specified by:
empty in interface Stack

full

public boolean full()
always return false.

Specified by:
full in interface Stack

push

public csc241.samples.Stack.Stack push(java.lang.Object x)
                                throws stackException
add an element to the top of the stack.
Create a new dynamicStack bound to temp; assign its topElement_ to x and its restOfStack_ to this. Then, return temp.
x - the new Object to be added

Specified by:
push in interface Stack
Throws:
- - Exception if stack is full.
stackException

pop

public csc241.samples.Stack.Stack pop()
                               throws stackException
remove an element from the top of the stack.
Simply, return restOfStack_.

Specified by:
pop in interface Stack
Throws:
- - Exception if stack is empty.
stackException

top

public java.lang.Object top()
return the element on top of the stack.
return topElement_; by design, this method return null if the Stack is empty.

Specified by:
top in interface Stack