all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
18
Task/Stack/Scala/stack.scala
Normal file
18
Task/Stack/Scala/stack.scala
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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