Skip to content
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ This file lists everyone, who contributed to this repo and wanted to show up her
- Trashtalk
- Cyrus Burt
- Patrik Tesarik
- Ken Power
4 changes: 4 additions & 0 deletions book.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@
"lang": "f90",
"name": "Fortran90"
},
{
"lang": "scala",
"name": "Scala"
},
{
"lang": "emojic",
"name": "Emojicode"
Expand Down
4 changes: 4 additions & 0 deletions contents/bubble_sort/bubble_sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
[import:5-9, lang:"nim"](code/nim/bubble_sort.nim)
{% sample lang="f90" %}
[import:19-40, lang:"fortran"](code/fortran/bubble.f90)
{% sample lang="scala" %}
[import:3-14, lang:"scala"](code/scala/bubble_sort.scala)
{% sample lang="emojic" %}
[import:2-14, lang:"emojicode"](code/emojicode/bubble_sort.emojic)
{% endmethod %}
Expand Down Expand Up @@ -111,6 +113,8 @@ Trust me, there are plenty of more complicated algorithms that do precisely the
[import, lang:"nim"](code/nim/bubble_sort.nim)
{% sample lang="f90" %}
[import, lang:"fortran"](code/fortran/bubble.f90)
{% sample lang="scala" %}
[import, lang:"scala"](code/scala/bubble_sort.scala)
{% sample lang="emojic" %}
[import, lang:"emojicode"](code/emojicode/bubble_sort.emojic)
{% endmethod %}
Expand Down
22 changes: 22 additions & 0 deletions contents/bubble_sort/code/scala/bubble_sort.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
object BubbleSort {

def bubbleDown(list: List[Int]): List[Int] =
list match {
case a :: b :: tail if a < b => b :: bubbleDown(a :: tail)
case a :: b :: tail => a :: bubbleDown(b :: tail)
case _ => list
}

def bubbleSort(list: List[Int]): List[Int] =
bubbleDown(list) match {
case unsorted :+ smallest => smallest :: bubbleDown(unsorted)
case _ => list
}

def main(args: Array[String]): Unit = {
val unsorted = List(9, 2, 0, 5, 3, 8, 1, 9, 4, 0, 7, 0, 9, 9, 0)

println("Unsorted list is " + unsorted)
println(" Sorted list is " + bubbleSort(unsorted))
}
}