scala.collection.immutable

class Stack

[source: scala/collection/immutable/Stack.scala]

@serializable

class Stack[+A]
extends Seq[A]
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
Direct Known Subclasses:
Stack.Node

Method Summary
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.
def + [B >: A](elem : B) : Stack[B]
Push an element on the stack.
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.
override 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).
override def equals (obj : Any) : Boolean
Compares this stack with the given object.
override def hashCode : Int
Returns the hash code for this stack.
override 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. The last element of the sequence will be on top of the new stack.
override def stringPrefix : java.lang.String
Redefines the prefix of the string representation.
def top : A
Returns the top element of the stack. An error is signaled if there is no element on the stack.
Methods inherited from Seq
lengthCompare, size, concat, last, lastOption, headOption, ++, isDefinedAt, lastIndexOf, map, flatMap, filter, take, drop, slice, takeWhile, dropWhile, reverse, contains, subseq, toArray, projection, equalsWith, startsWith, endsWith, indexOf, containsSlice
Methods inherited from Collection
toString
Methods inherited from Iterable
partition, foreach, forall, exists, find, findIndexOf, indexOf, foldLeft, foldRight, /:, :\, reduceLeft, reduceRight, copyToBuffer, sameElements, toList, toStream, mkString, mkString, mkString, addString, addString, copyToArray, hasDefiniteSize
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from AnyRef
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Class Summary
protected class Node [+B >: A](elem : B) extends Stack[B]
Method Details
override def isEmpty : Boolean
Checks if this stack is empty.
Returns
true, iff there is no element on the stack.
Overrides
Seq.isEmpty

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

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.

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.

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.

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

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.

override 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.

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.

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

override def stringPrefix : java.lang.String
Redefines the prefix of the string representation.