RosettaCodeData/Task/Stack/Scala/stack-1.scala
Ingy döt Net 776bba907c Sync
2013-10-27 22:24:23 +00:00

17 lines
358 B
Scala

class Stack[T] {
private var items = List[T]()
def isEmpty = items.isEmpty
def peek = items match {
case List() => error("Stack empty")
case head :: rest => head
}
def pop = items match {
case List() => error("Stack empty")
case head :: rest => items = rest; head
}
def push(value: T) = items = value +: items
}