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.
override 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](elems : Iterator[B]) : Stack[B]
Push all elements provided by the given iterator object onto the stack. The last element returned by the iterable object will be on top of the new stack.
def apply (n : Int) : A
Returns the n-th element of this stack. The bottom element has index 0, elements above 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](elem : B) : Stack[B]
Push an element on the stack.
def push [B >: A](elem1 : B, elem2 : B, 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.
def push [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.
override def reverse : Stack[A]
A stack consisting of all elements of this stack in reverse order.
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, first, firstOption, headOption, isDefinedAt, lastIndexOf, findIndexOf, indexOf, map, flatMap, filter, take, drop, slice, slice, takeWhile, dropWhile, contains, subseq, toArray, toSeq, projection, equalsWith, startsWith, startsWith, endsWith, indexOf, containsSlice
Methods inherited from Collection
toString
Methods inherited from Iterable
partition, foreach, forall, exists, find, foldLeft, foldRight, /:, :\, reduceLeft, reduceRight, copyToBuffer, sameElements, toList, toStream, mkString, mkString, mkString, addString, 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

@deprecated

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

def push[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 push[B >: A](elem1 : B, elem2 : B, 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.

@deprecated

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.
Deprecated
Use the method push from now on.
Parameters
elems - the iterable object.
Returns
the stack with the new elements on top.

def push[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 ++[B >: A](elems : Iterator[B]) : Stack[B]
Push all elements provided by the given iterator object onto the stack. The last element returned by the iterable object will be on top of the new stack.
Parameters
elems - the iterator object.
Returns
the stack with the new elements on top.
Deprecated

override 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.
Overrides
Seq.++

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 bottom element has index 0, elements above 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 reverse : Stack[A]
A stack consisting of all elements of this stack in reverse order.
Overrides
Seq.reverse

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.