【发布时间】:2018-07-26 13:26:55
【问题描述】:
我正在编写一个函数来执行插入排序。在编写代码时,我再次得到与输出相同的列表。
def insertionSort(xs: List[Int]): List[Int] =
{
if (xs.isEmpty) Nil
else insert(xs.head, 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)
}
谁能告诉我哪里出错了。
【问题讨论】:
标签: scala insertion-sort