package examples

object sort2 {

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

  def main(args: Array[String]) {
    val xs = List(6, 2, 8, 5, 1, 8)
    println(xs)
    println(sort(xs))
  }

}

package examples

object sort2 {

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

  def main(args: Array[String]) {
    val xs = List(6, 2, 8, 5, 1)
    println(xs)
    println(sort(xs))
  }

}

--- 
+++ 
@@ -11,13 +11,13 @@
       def gtPivot(x: Int) = x > pivot
       def eqPivot(x: Int) = x == pivot
       sort(a filter lePivot) :::
-           sort(a filter eqPivot) :::
+           (a filter eqPivot) :::
            sort(a filter gtPivot)
     }
   }
 
   def main(args: Array[String]) {
-    val xs = List(6, 2, 8, 5, 1)
+    val xs = List(6, 2, 8, 5, 1, 8)
     println(xs)
     println(sort(xs))
   }
Fix bug in example sort.

Embarrassing bug causes sort to explode if there are any duplicated
elements. Closes SI-4961, no review.

