in scala/collection/immutable
class Stack

class Stack[A]()
extends Object
with ScalaObject
with Seq[A]
Implementing classes or objects:
class Node[B >: A](elem: B) in scala/collection/immutable/Stack-class

This class implements immutable stacks using a list-based data structure. Instances of Stack represent empty stacks; they can be either created by calling the constructor directly, or by applying the function Stack.Empty.
Author:
Matthias Zenger
Version:
1.0, 10/07/2003

Method Summary
  def +[B >: A](elem: B): Stack[B]
     Push an element on the stack.
  def +[B >: A](elems: Iterable[B]): Stack[B]
     Push all elements provided by the given iterable object onto the stack.
  def apply(n: Int): A
     Returns the n-th element of this stack.
  def elements: Iterator[A]
     Returns an iterator over all elements on the stack.
override def equals(obj: Any): Boolean
     Compares this stack with the given object.
override def hashCode(): Int
     Returns the hash code for this stack.
  def isEmpty: Boolean
     Checks if this stack is empty.
  def length: Int
     Returns the size of this stack.
  def pop: Stack[A]
     Removes the top element from the stack.
  def push[B >: A](elems: B*): Stack[B]
     Push a sequence of elements onto the stack.
override def toList: List[A]
     Creates a list of all stack elements in LIFO order.
  def top: A
     Returns the top element of the stack.

Methods inherited from java/lang/Object-class
clone, eq, finalize, getClass, notify, notifyAll, synchronized, wait, wait, wait

Methods inherited from scala/Any-class
!=, ==, asInstanceOf, isInstanceOf, match

Methods inherited from scala/Iterable-class
/:, :\, exists, find, foldLeft, foldRight, forall, foreach, sameElements

Methods inherited from scala/Seq-class
copyToArray, drop, indexOf, isDefinedAt, lastIndexOf, stringPrefix, subseq, take, toString

Class Summary
protected class Node[B >: A](elem: B)

Method Detail

isEmpty

  def isEmpty: Boolean
Checks if this stack is empty.
Returns:
true, iff there is no element on the stack.

length

  def length: Int
Returns the size of this stack.
Returns:
the stack size.

+

  def +[B >: A](elem: B): Stack[B]
Push an element on the stack.
Parameters:
elem - the element to push on the stack.
Returns:
the stack with the new element on top.

+

  def +[B >: A](elems: Iterable[B]): Stack[B]
Push all elements provided by the given iterable object onto the stack. The last element returned by the iterable object will be on top of the new stack.
Parameters:
elems - the iterable object.
Returns:
the stack with the new elements on top.

push

  def push[B >: A](elems: B*): Stack[B]
Push a sequence of elements onto the stack. The last element of the sequence will be on top of the new stack.
Parameters:
elems - the element sequence.
Returns:
the stack with the new elements on top.

top

  def top: A
Returns the top element of the stack. An error is signaled if there is no element on the stack.
Returns:
the top element.

pop

  def pop: Stack[A]
Removes the top element from the stack.
Returns:
the new stack without the former top element.

apply

  def apply(n: Int): A
Returns the n-th element of this stack. The top element has index 0, elements below are indexed with increasing numbers.
Parameters:
n - the index number.
Returns:
the n-th element on the stack.

elements

  def elements: Iterator[A]
Returns an iterator over all elements on the stack. The iterator issues elements in the reversed order they were inserted into the stack (LIFO order).
Returns:
an iterator over all stack elements.

toList

  override def toList: List[A]
Creates a list of all stack elements in LIFO order.
Returns:
the created list.

equals

  override def equals(obj: Any): Boolean
Compares this stack with the given object.
Returns:
true, iff the two stacks are equal; i.e. they contain the same elements in the same order.

hashCode

  override def hashCode(): Int
Returns the hash code for this stack.
Returns:
the hash code of the stack.