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