600000007

プログラムと折り紙のブログです。

Scala by Example‎ > 演習9.1.1解答案

Scala by Example > 演習9.1.1の解答案です。

  def isort(xs: List[Int]): List[Int] = xs match {
    case List() => List()
    case x :: xs1 => insert(x, isort(xs1))
  }
  def insert(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)
  }

すいませんほぼカンニング状態です。
すぐ下に答えが書いてありますね。