Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
17
Task/Stack/Scala/stack-1.scala
Normal file
17
Task/Stack/Scala/stack-1.scala
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue