Scala实现快速排序
代码
scala>:paste//Entering paste mode (ctrl-D to finish)def qSort(a:List[Int]):List[Int]=if(a.length<2) aelseqSort(a.filter(_<a.head))++a.filter(_ == a.head)++qSort(a.filter(_>a.head))//Exiting paste mode, now interpreting.qSort:(a:List[Int])List[Int]scala> qSort(List(3,1,2))res47:List[Int]=List(1,2,3)scala> qSort(List(3,8,5,31,1,2))res48:List[Int]=List(1,2,3,5,8,31)