summaryrefslogtreecommitdiff
path: root/sources/examples/sort2.scala
blob: a4e32a9cd4938d252dcc6a6627c550f4a952ddde (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
module sorter {

def sort (a: List[Int]): List[Int] = {
  val pivot = a at (a.length / 2);
  def leqPivot(x: Int) = x <= pivot;
  def gtPivot(x: Int) = x > pivot;
  def eqPivot(x: Int) = x == pivot;
  sort(a filter leqPivot)
    ::: sort(a filter eqPivot)
    ::: sort(a filter gtPivot)
}
}