This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ListInsertion extends App { | |
/** | |
* non tail-recursive version | |
*/ | |
def insert1[T](l: List[T], v: T)(implicit ord: Ordering[T]): List[T] = l match { | |
case List() => List(v) | |
case x :: xs => | |
if (ord.lt(x, v)) x :: insert1(xs, v) | |
else v :: l | |
} |