summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2003-12-04 10:34:13 +0000
committermichelou <michelou@epfl.ch>2003-12-04 10:34:13 +0000
commita85cabb4c93c37f2ba4adc2ae405b2a2d737f8a2 (patch)
tree117085cf31d60b751f25186e685708420c088749 /sources
parent6dac101d485b111e21dd77ec3eee726a7d93f2db (diff)
downloadscala-a85cabb4c93c37f2ba4adc2ae405b2a2d737f8a2.tar.gz
scala-a85cabb4c93c37f2ba4adc2ae405b2a2d737f8a2.tar.bz2
scala-a85cabb4c93c37f2ba4adc2ae405b2a2d737f8a2.zip
- fixed code for empty arrays
Diffstat (limited to 'sources')
-rw-r--r--sources/examples/sort.scala14
1 files changed, 9 insertions, 5 deletions
diff --git a/sources/examples/sort.scala b/sources/examples/sort.scala
index 661ae0a414..56dcadb76b 100644
--- a/sources/examples/sort.scala
+++ b/sources/examples/sort.scala
@@ -22,13 +22,17 @@ object sorter {
if (j < r) sort1(i, r);
}
- sort1(0, a.length - 1);
+ if (a.length > 0)
+ sort1(0, a.length - 1);
}
def println(ar: Array[Int]) = {
- def iter(i: Int): String =
- ar(i) + (if (i < ar.length-1) "," + iter(i+1) else "]");
- Console.println("[" + iter(0));
+ def print1 = {
+ def iter(i: Int): String =
+ ar(i) + (if (i < ar.length-1) "," + iter(i+1) else "");
+ if (ar.length == 0) "" else iter(0)
+ }
+ Console.println("[" + print1 + "]");
}
def main(args: Array[String]) = {
@@ -39,4 +43,4 @@ object sorter {
println(ar);
}
-} \ No newline at end of file
+}