diff options
Diffstat (limited to 'sources/examples/sort2.scala')
-rw-r--r-- | sources/examples/sort2.scala | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/sources/examples/sort2.scala b/sources/examples/sort2.scala new file mode 100644 index 0000000000..a4e32a9cd4 --- /dev/null +++ b/sources/examples/sort2.scala @@ -0,0 +1,12 @@ +module sorter { + +def sort (a: List[Int]): List[Int] = { + val pivot = a at (a.length / 2); + def leqPivot(x: Int) = x <= pivot; + def gtPivot(x: Int) = x > pivot; + def eqPivot(x: Int) = x == pivot; + sort(a filter leqPivot) + ::: sort(a filter eqPivot) + ::: sort(a filter gtPivot) +} +}
\ No newline at end of file |