scala.collection.immutable

class Stack

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

@serializable

@SerialVersionUID(1976480595012942526L)

class Stack[+A](protected val elems : List[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.
Notes
This class exists only for historical reason and as an analogue of mutable stacks Instead of an immutable stack you can just use a list.
Author
Matthias Zenger
Version
1.0, 10/07/2003
Since
1
Additional Constructor Summary
def this : Stack[A]
Method Summary
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 hashCode : Int
Returns the hash code for this stack.
override def isEmpty : Boolean
Checks if this stack is empty.
override def iterator : 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).
def length : Int
The number of elements in the stack
def pop : Stack[A]
Removes the top element from the stack. Note: should return (A, Stack[A]) as for queues (mics)
def pop2 : (A, Stack[A])
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 pushAll [B >: A](elems : Traversable[B]) : Stack[B]
Push all elements provided by the given traversable object onto the stack. The last element returned by the iterable object will be on top of the new stack.
def pushAll [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.
override def toString : java.lang.String
Returns a string representation of this stack.
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
companion
Methods inherited from SeqLike
thisCollection, toCollection, lengthCompare, size, isDefinedAt, segmentLength, prefixLength, indexWhere, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, lastIndexWhere, reverse, reverseMap, reverseIterator, reversedElements, startsWith, startsWith, endsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, contains, union, diff, intersect, removeDuplicates, patch, updated, +:, :+, padTo, sortWith, sortWith, sortBy, toSeq, indices, view, view, equals, findLastIndexOf, equalsWith, containsSlice, projection
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from IterableLike
elements, foreach, forall, exists, find, foldRight, reduceRight, toIterable, head, take, slice, takeWhile, takeRight, dropRight, copyToArray, zip, zipAll, zipWithIndex, sameElements, toStream, canEqual, first, firstOption
Methods inherited from GenericTraversableTemplate
newBuilder, genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableLike
repr, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, partialMap, remove, partition, groupBy, count, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, tail, last, lastOption, init, drop, dropWhile, span, splitAt, copyToBuffer, copyToArray, toArray, toList, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, addString, stringPrefix, withFilter
Methods inherited from AnyRef
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Additional Constructor Details
def this : Stack[A]

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

def length : Int
The number of elements in the stack

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.

def pushAll[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.

def pushAll[B >: A](elems : Traversable[B]) : Stack[B]
Push all elements provided by the given traversable 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 top : A
Returns the top element of the stack. An error is signaled if there is no element on the stack.
Throws
Predef.NoSuchElementException -
Returns
the top element.

def pop : Stack[A]
Removes the top element from the stack. Note: should return (A, Stack[A]) as for queues (mics)
Throws
Predef.NoSuchElementException -
Returns
the new stack without the former top element.

def pop2 : (A, Stack[A])

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.
Throws
Predef.NoSuchElementException -
Parameters
n - the index number.
Returns
the n-th element on the stack.

override def iterator : 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 hashCode : Int
Returns the hash code for this stack.
Returns
the hash code of the stack.

override def toString : java.lang.String
Returns a string representation of this stack.