summaryrefslogtreecommitdiff
path: root/sources/examples/sort1.scala
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2003-11-28 17:04:18 +0000
committermichelou <michelou@epfl.ch>2003-11-28 17:04:18 +0000
commitdaea8b76a5f9dd35e54f4d524691187850202182 (patch)
tree69409f806b178c804446def99b96f7a017d3cdf9 /sources/examples/sort1.scala
parent6b8d116ec9f10e97fd2fb3baf7ebd99af0ebedf2 (diff)
downloadscala-daea8b76a5f9dd35e54f4d524691187850202182.tar.gz
scala-daea8b76a5f9dd35e54f4d524691187850202182.tar.bz2
scala-daea8b76a5f9dd35e54f4d524691187850202182.zip
- updated to current Scala compiler
- added main() for testing
Diffstat (limited to 'sources/examples/sort1.scala')
-rw-r--r--sources/examples/sort1.scala22
1 files changed, 15 insertions, 7 deletions
diff --git a/sources/examples/sort1.scala b/sources/examples/sort1.scala
index f2722b23cc..13a7b3e568 100644
--- a/sources/examples/sort1.scala
+++ b/sources/examples/sort1.scala
@@ -1,12 +1,20 @@
-import scala._;
-
-module sorter {
+object sorter {
def sort(a: List[Int]): List[Int] = {
- val pivot = a at (a.length / 2);
- sort(a.filter(x => x < pivot))
- ::: a.filter(x => x == pivot)
- ::: sort(a.filter(x => x > pivot))
+ if (a.length < 2)
+ a
+ else {
+ val pivot = a(a.length / 2);
+ sort(a.filter(x => x < pivot))
+ ::: a.filter(x => x == pivot)
+ ::: sort(a.filter(x => x > pivot))
+ }
+ }
+
+ def main(args: Array[String]) = {
+ val xs = List(6, 2, 8, 5, 1);
+ Console.println(xs);
+ Console.println(sort(xs));
}
} \ No newline at end of file