kodkod.util.collections
Class LinkedStack<T>

java.lang.Object
  extended by kodkod.util.collections.Stack<T>
      extended by kodkod.util.collections.LinkedStack<T>
All Implemented Interfaces:
java.lang.Iterable<T>

public final class LinkedStack<T>
extends Stack<T>

A Stack implementation based on a singly linked list.

Author:
Emina Torlak

Constructor Summary
LinkedStack()
          Constructs an empty stack.
 
Method Summary
 boolean empty()
          Returns true if the stack is empty; otherwise returns false.
 java.util.Iterator<T> iterator()
          Iterates over the items in this LinkedStack, starting at the top of the stack and working its way down.
 T peek()
          Looks at the object at the top of this stack without removing it from the stack.
 T pop()
          Removes the object at the top of this stack and returns that object as the value of this function.
 T push(T item)
          Pushes an item onto the top of this stack and returns it.
 int search(java.lang.Object o)
          Returns the 1-based position where an object is on this stack.
 int size()
          Returns the size of this stack.
 
Methods inherited from class kodkod.util.collections.Stack
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LinkedStack

public LinkedStack()
Constructs an empty stack.

effects:
no this.elems'
Method Detail

size

public int size()
Description copied from class: Stack
Returns the size of this stack.

Specified by:
size in class Stack<T>
Returns:
this.size
See Also:
Stack.size()

push

public T push(T item)
Pushes an item onto the top of this stack and returns it.

Specified by:
push in class Stack<T>
Returns:
item
effects:
this.size' = this.size + 1 && this.elems'[0] = item && all i: [0..this.size) | this.elems'[i+1] = this.elems[i]

pop

public T pop()
Removes the object at the top of this stack and returns that object as the value of this function.

Specified by:
pop in class Stack<T>
Returns:
this.elems[0]
Throws:
java.util.EmptyStackException - - no this.elems
effects:
this.size' = this.size - 1 && all i: [1..this.size) | this.elems'[i-1] = this.elems[i]

peek

public T peek()
Looks at the object at the top of this stack without removing it from the stack.

Specified by:
peek in class Stack<T>
Returns:
this.elems[0]
Throws:
java.util.EmptyStackException - - no this.elems

search

public int search(java.lang.Object o)
Returns the 1-based position where an object is on this stack. If the object o occurs as an item in this stack, this method returns the distance from the top of the stack of the occurrence nearest the top of the stack; the topmost item on the stack is considered to be at distance 1. The equals method is used to compare o to the items in this stack.

Specified by:
search in class Stack<T>
Returns:
o in this.elems[int] => min(this.elems.o) + 1, -1

empty

public boolean empty()
Returns true if the stack is empty; otherwise returns false.

Specified by:
empty in class Stack<T>
Returns:
no this.elems

iterator

public java.util.Iterator<T> iterator()
Iterates over the items in this LinkedStack, starting at the top of the stack and working its way down.

Specified by:
iterator in interface java.lang.Iterable<T>
Specified by:
iterator in class Stack<T>
Returns:
iterator over the elements in this stack.