datastructures

net.datastructures
Class NodeStack

java.lang.Object
  extended bynet.datastructures.NodeStack
All Implemented Interfaces:
Stack

public class NodeStack
extends Object
implements Stack

Implementation of a stack by means of a singly linked list.

Author:
Natasha Gelfand
See Also:
Node

Field Summary
protected  int size
           
protected  Node top
           
 
Constructor Summary
NodeStack()
          Creates an empty stack.
 
Method Summary
 boolean isEmpty()
          Return whether the stack is empty.
 Object pop()
          Remove the top element from the stack.
 void push(Object elem)
          Insert an element at the top of the stack.
 int size()
          Return the number of elements in the stack.
 Object top()
          Inspect the element at the top of the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

top

protected Node top

size

protected int size
Constructor Detail

NodeStack

public NodeStack()
Creates an empty stack.

Method Detail

size

public int size()
Description copied from interface: Stack
Return the number of elements in the stack.

Specified by:
size in interface Stack
Returns:
number of elements in the stack.

isEmpty

public boolean isEmpty()
Description copied from interface: Stack
Return whether the stack is empty.

Specified by:
isEmpty in interface Stack
Returns:
true if the stack is empty, false otherwise.

push

public void push(Object elem)
Description copied from interface: Stack
Insert an element at the top of the stack.

Specified by:
push in interface Stack
Parameters:
elem - element to be inserted.

top

public Object top()
           throws EmptyStackException
Description copied from interface: Stack
Inspect the element at the top of the stack.

Specified by:
top in interface Stack
Returns:
top element in the stack.
Throws:
EmptyStackException - if the stack is empty.

pop

public Object pop()
           throws EmptyStackException
Description copied from interface: Stack
Remove the top element from the stack.

Specified by:
pop in interface Stack
Returns:
element removed.
Throws:
EmptyStackException - if the stack is empty.

datastructures