summaryrefslogtreecommitdiff
path: root/docs/examples/sort2.scala
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2005-12-16 18:44:33 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2005-12-16 18:44:33 +0000
commit53a3cc7b17f4cf97075b7e71720777fd84109696 (patch)
tree0cc784e0b47ea49cc151a136d19f20bfa8ee2197 /docs/examples/sort2.scala
parentdf50e05006b43b007c2587549030d24b5c154398 (diff)
downloadscala-53a3cc7b17f4cf97075b7e71720777fd84109696.tar.gz
scala-53a3cc7b17f4cf97075b7e71720777fd84109696.tar.bz2
scala-53a3cc7b17f4cf97075b7e71720777fd84109696.zip
Created proper 'docs' folder for new layout.
Diffstat (limited to 'docs/examples/sort2.scala')
-rw-r--r--docs/examples/sort2.scala25
1 files changed, 25 insertions, 0 deletions
diff --git a/docs/examples/sort2.scala b/docs/examples/sort2.scala
new file mode 100644
index 0000000000..53b2f89174
--- /dev/null
+++ b/docs/examples/sort2.scala
@@ -0,0 +1,25 @@
+package examples;
+
+object sort2 {
+
+ def sort(a: List[Int]): List[Int] = {
+ if (a.length < 2)
+ a
+ else {
+ val pivot = a(a.length / 2);
+ def lePivot(x: Int) = x < pivot;
+ def gtPivot(x: Int) = x > pivot;
+ def eqPivot(x: Int) = x == pivot;
+ sort(a filter lePivot)
+ ::: sort(a filter eqPivot)
+ ::: sort(a filter gtPivot)
+ }
+ }
+
+ def main(args: Array[String]) = {
+ val xs = List(6, 2, 8, 5, 1);
+ Console.println(xs);
+ Console.println(sort(xs))
+ }
+
+}