blob: 77fa36a0528b82c1f878858332eab3ed41537efe (
plain) (
tree)
|
|
package examples;
object sorter {
def sort(a: List[Int]): List[Int] = {
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))
}
}
|