summaryrefslogtreecommitdiffstats
path: root/Scala/sandbox/9-lists.scala
diff options
context:
space:
mode:
Diffstat (limited to 'Scala/sandbox/9-lists.scala')
-rw-r--r--Scala/sandbox/9-lists.scala19
1 files changed, 19 insertions, 0 deletions
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)
+ }
+}