scranton.stack
Class StackViaLinear1Ind

java.lang.Object
  extended byscranton.Linear1
      extended byscranton.Linear1Ind
          extended byscranton.stack.StackViaLinear1Ind
All Implemented Interfaces:
Stack

public class StackViaLinear1Ind
extends Linear1Ind
implements Stack

An implementation of the Stack interface via extension of the Linear1Ind class. Invariant: The class warranty is voided is a client directly applies any Linear1Ind class method.


Field Summary
 
Fields inherited from class scranton.Linear1
data, link
 
Constructor Summary
  StackViaLinear1Ind()
          Constructs an empty stack by extending the Linear1Indclass.
protected StackViaLinear1Ind(java.lang.Object obj)
          This constructor is for use by extensions of this class.
 
Method Summary
 Linear1 factory()
          Returns a null Linear1() object
 boolean isEmpty()
          Stack does not change, returns true iff the stack is empty.
 java.lang.Object pop()
          Decrease the size of the stack by one by removing and returning the object at the top.
 void push(java.lang.Object item)
          Increase the size of the stack by one by placing item as the new top of the stack.
 java.lang.Object topOf()
          Stack does not change, returns the reference to the top object in the stack.
 java.lang.String toString()
          Returns a string representation of the stack.
 
Methods inherited from class scranton.Linear1Ind
indInsert, indRemove, indReplace, indView
 
Methods inherited from class scranton.Linear1
getData, getLink, setData, setLink
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StackViaLinear1Ind

public StackViaLinear1Ind()
Constructs an empty stack by extending the Linear1Indclass.


StackViaLinear1Ind

protected StackViaLinear1Ind(java.lang.Object obj)
This constructor is for use by extensions of this class. Constructs a stack with the indicated object.

Method Detail

isEmpty

public boolean isEmpty()
Description copied from interface: Stack
Stack does not change, returns true iff the stack is empty.

Specifications:
S'=S
Return S==()

Specified by:
isEmpty in interface Stack
Returns:
boolean this==().

topOf

public java.lang.Object topOf()
Description copied from interface: Stack
Stack does not change, returns the reference to the top object in the stack.

Specifications:
S!=()
S'=S

Return an-1

Specified by:
topOf in interface Stack
Returns:
Object Top of stack.

push

public void push(java.lang.Object item)
Description copied from interface: Stack
Increase the size of the stack by one by placing item as the new top of the stack.

Specifications:
S'=(S, obj)

Specified by:
push in interface Stack
Parameters:
item - The new top of stack

pop

public java.lang.Object pop()
Description copied from interface: Stack
Decrease the size of the stack by one by removing and returning the object at the top. Note: that the stack cannot be empty.

Specifications:
S!=()
S = (S', an-1)
Return: an-1

Specified by:
pop in interface Stack
Returns:
Object Top of stack.

factory

public Linear1 factory()
Description copied from class: Linear1
Returns a null Linear1() object

Overrides:
factory in class Linear1
Returns:
A null Linear1() object

toString

public java.lang.String toString()
Description copied from interface: Stack
Returns a string representation of the stack. The format is, "TOP[Otop\t...\tObottom]BOTTOM"

Specified by:
toString in interface Stack
Overrides:
toString in class Linear1Ind
Returns:
String Returns a tab delimited string of the objects in the recursive Linear1 structure.