scranton.stack
Interface Stack

All Known Implementing Classes:
StackViaArray, StackViaLinear1, StackViaLinear1Ind

public interface Stack

Specifications for a (pushdown) stack, the semi-formal notation for specifications appears on the notation page.

Specifications:
A stack S is
  • Empty, S = ()
  • Otherwise, S = (a0, a1, ..., an-1), an-1 is the top of the stack and a0 is the bottom

Initial Value:
Initial value: S=()


Method Summary
 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.
 

Method Detail

isEmpty

public boolean isEmpty()
Stack does not change, returns true iff the stack is empty.

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

Returns:
boolean this==().

topOf

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

Specifications:
S!=()
S'=S

Return an-1

Returns:
Object Top of stack.
Throws:
Assertion - When stack is empty

push

public void push(java.lang.Object item)
Increase the size of the stack by one by placing item as the new top of the stack.

Specifications:
S'=(S, obj)

Parameters:
item - The new top of stack

pop

public java.lang.Object pop()
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

Returns:
Object Top of stack.
Throws:
Assertion - When stack is empty

toString

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

Returns:
A string representation of the stack.