scala.collection.mutable

class Stack

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

@serializable

@cloneable

class Stack[A](val elems : List[A])
extends Seq[A] with Cloneable[Stack[A]]
A stack implements a data structure which allows to store and retrieve objects in a last-in-first-out (LIFO) fashion.
Author
Matthias Zenger
Martin Odersky
Version
2.8
Since
1
Direct Known Subclasses:
StackProxy, SynchronizedStack

Additional Constructor Summary
def this : Stack[A]
Method Summary
def ++= (it : Iterable[A]) : Stack[A]
def ++= (it : Iterator[A]) : Stack[A]
override def apply (index : Int) : A
Retrieve n'th element from stack, where top of stack has index 0
def clear : Unit
Removes all elements from the stack. After this operation completed, the stack will be empty.
override def clone : Stack[A]
This method clones the stack.
override def isEmpty : Boolean
Checks if the stack is empty.
override def iterator : Iterator[A]
Returns an iterator over all elements on the stack. This iterator is stable with respect to state changes in the stack object; i.e. such changes will not be reflected in the iterator. The iterator issues elements in the reversed order they were inserted into the stack (LIFO order).
override def length : Int
The number of elements in the stack
def pop : A
Removes the top element from the stack.
def push (elem1 : A, elem2 : A, elems : A*) : Stack[A]
Push two or more elements onto the stack. The last element of the sequence will be on top of the new stack.
def push (elem : A) : Stack[A]
Push an element on the stack.
def pushAll (elems : Iterator[A]) : Stack[A]
Push all elements provided by the given iterator object onto the stack. The last element returned by the iterator will be on top of the new stack.
def pushAll (elems : Traversable[A]) : Stack[A]
Push all elements provided by the given iterable object onto the stack. The last element returned by the traversable object will be on top of the new 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. This method will not remove the element from 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, hashCode, equals, toString, findLastIndexOf, equalsWith, containsSlice, projection
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, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, addString, stringPrefix, withFilter
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from AnyRef
getClass, 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 the stack is empty.
Returns
true, iff there is no element on the stack

override def length : Int
The number of elements in the stack

override def apply(index : Int) : A
Retrieve n'th element from stack, where top of stack has index 0

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

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

@deprecated("use pushAll")

def ++=(it : Iterator[A]) : Stack[A]

@deprecated("use pushAll")

def ++=(it : Iterable[A]) : Stack[A]

def top : A
Returns the top element of the stack. This method will not remove the element from the stack. An error is signaled if there is no element on the stack.
Throws
Predef.NoSuchElementException -
Returns
the top element

def pop : A
Removes the top element from the stack.
Throws
Predef.NoSuchElementException -
Returns
the top element

def clear : Unit
Removes all elements from the stack. After this operation completed, the stack will be empty.

override def iterator : Iterator[A]
Returns an iterator over all elements on the stack. This iterator is stable with respect to state changes in the stack object; i.e. such changes will not be reflected in the iterator. 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 toList : List[A]
Creates a list of all stack elements in LIFO order.
Returns
the created list.

override def clone : Stack[A]
This method clones the stack.
Returns
a stack with the same elements.
Overrides
Cloneable.clone