From 12ef23e6da7b7186bec20d426c087d757260659d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 28 Apr 2013 00:30:49 +0200 Subject: Scala : sandbox Scala : add 9-lists --- Scala/sandbox/0-main.scala | 1 + Scala/sandbox/9-lists.scala | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 Scala/sandbox/9-lists.scala diff --git a/Scala/sandbox/0-main.scala b/Scala/sandbox/0-main.scala index b68b57e..2616f8f 100644 --- a/Scala/sandbox/0-main.scala +++ b/Scala/sandbox/0-main.scala @@ -11,5 +11,6 @@ object Main extends App { Natural.run Variance.run PatternMatching.run + Lists.run } diff --git a/Scala/sandbox/9-lists.scala b/Scala/sandbox/9-lists.scala new file mode 100644 index 0000000..7694169 --- /dev/null +++ b/Scala/sandbox/9-lists.scala @@ -0,0 +1,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) + } +} -- cgit v1.1-2-g2b99