`
cakin24
  • 浏览: 1333150 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

Scala实现快速排序

阅读更多

代码

  1. scala>:paste
  2. //Entering paste mode (ctrl-D to finish)
  3. def qSort(a:List[Int]):List[Int]=
  4. if(a.length<2) a
  5. else
  6. qSort(a.filter(_<a.head))++
  7. a.filter(_ == a.head)++
  8. qSort(a.filter(_>a.head))
  9. //Exiting paste mode, now interpreting.
  10. qSort:(a:List[Int])List[Int]
  11. scala> qSort(List(3,1,2))
  12. res47:List[Int]=List(1,2,3)
  13. scala> qSort(List(3,8,5,31,1,2))
  14. res48:List[Int]=List(1,2,3,5,8,31)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics