scala 实现算法

快速排序

def sort(xs: Array[Int]): Array[Int] =
  if (xs.length <= 1) xs
  else {
    val pivot = xs(xs.length / 2)
    Array.concat(
      sort(xs filter (pivot >)),
           xs filter (pivot ==),
      sort(xs filter (pivot <)))
  }

 

posted @ 2015-12-05 11:25  zhanggl  阅读(412)  评论(0编辑  收藏  举报