首页 > 编程语言 > 详细

列表2中插入排序

时间:2018-09-02 13:52:14      阅读:189      评论:0      收藏:0      [点我收藏+]
 //插入排序
 def isort(xs:List[Int]):List[Int]=
   if(xs.isEmpty)Nil
   else insert(xs.head,isort(xs.tail))
 def insert(x:Int,xs:List[Int]):List[Int]=
   if(xs.isEmpty || x<=xs.head) x::xs
   else xs.head :: insert(x,xs.tail)
  //模式匹配插入排序
  def isort1(xs:List[Int]):List[Int]=xs match{
     case List() =>List()
     case x::xsl=>insert(x,isort(xsl))
   }
 def insert2(x:Int,xs:List[Int]):List[Int]=xs match{
   case List() =>List(x)
   case y::ys=>if(x<=y) x:: xs
   else y:: insert(x,ys)
 }

  

列表2中插入排序

原文:https://www.cnblogs.com/huiandong/p/9573560.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!