//插入排序
 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)
 }

  

相关文章:

  • 2021-09-13
  • 2022-12-23
  • 2021-04-08
  • 2022-12-23
  • 2021-10-27
  • 2022-01-02
  • 2021-11-04
  • 2021-06-04
猜你喜欢
  • 2021-06-21
  • 2021-07-25
  • 2021-07-10
  • 2021-11-06
  • 2022-01-11
  • 2021-10-28
相关资源
相似解决方案