summaryrefslogtreecommitdiffstats
path: root/Scala/sandbox/9-lists.scala
blob: 7694169f10e87cf4f24717390c84d463b397800d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
object Lists
{

  def isort(xs: List[Int]): List[Int] = xs match {
    case List() => List()
    case y :: ys => insert(y, isort(ys))
  }

  def insert(x: Int, xs: List[Int]): List[Int] = xs match {
    case List() => x :: Nil
    case y :: ys => if ( x < y ) x :: xs else y :: insert(x, ys)
  }

  def run = {
    println("Lists")
    val l = 3 :: 1 :: 8 :: 4 :: 9 :: Nil
    println(isort(l).toString)
  }
}