summaryrefslogtreecommitdiff
path: root/docs/examples/sort.scala
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-05-16 13:30:30 +0000
committermichelou <michelou@epfl.ch>2007-05-16 13:30:30 +0000
commit1f65685c9626929f3e6d7b81225f57fd4e68438c (patch)
tree54d3462ca86d36545ab6ef946a1095a0f15ac38f /docs/examples/sort.scala
parent73b2db5db4fc7316467b51299994b47065bde74d (diff)
downloadscala-1f65685c9626929f3e6d7b81225f57fd4e68438c.tar.gz
scala-1f65685c9626929f3e6d7b81225f57fd4e68438c.tar.bz2
scala-1f65685c9626929f3e6d7b81225f57fd4e68438c.zip
updated examples
Diffstat (limited to 'docs/examples/sort.scala')
-rw-r--r--docs/examples/sort.scala18
1 files changed, 9 insertions, 9 deletions
diff --git a/docs/examples/sort.scala b/docs/examples/sort.scala
index cc06f19366..9a928f1107 100644
--- a/docs/examples/sort.scala
+++ b/docs/examples/sort.scala
@@ -2,23 +2,23 @@ package examples
object sort {
- def sort(a: Array[Int]): Unit = {
+ def sort(a: Array[Int]) {
- def swap(i: Int, j: Int): Unit = {
+ def swap(i: Int, j: Int) {
val t = a(i); a(i) = a(j); a(j) = t
}
- def sort1(l: Int, r: Int): Unit = {
+ def sort1(l: Int, r: Int) {
val pivot = a((l + r) / 2)
var i = l
var j = r
while (i <= j) {
- while (a(i) < pivot) { i = i + 1 }
- while (a(j) > pivot) { j = j - 1 }
+ while (a(i) < pivot) { i += 1 }
+ while (a(j) > pivot) { j -= 1 }
if (i <= j) {
swap(i, j)
- i = i + 1
- j = j - 1
+ i += 1
+ j -= 1
}
}
if (l < j) sort1(l, j)
@@ -29,7 +29,7 @@ object sort {
sort1(0, a.length - 1)
}
- def println(ar: Array[Int]) = {
+ def println(ar: Array[Int]) {
def print1 = {
def iter(i: Int): String =
ar(i) + (if (i < ar.length-1) "," + iter(i+1) else "")
@@ -38,7 +38,7 @@ object sort {
Console.println("[" + print1 + "]")
}
- def main(args: Array[String]): Unit = {
+ def main(args: Array[String]) {
val ar = Array(6, 2, 8, 5, 1)
println(ar)
sort(ar)