Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@RyanSusana
Last active June 2, 2020 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanSusana/8e9217cf2a11c78237c3c8c577ba3221 to your computer and use it in GitHub Desktop.
Save RyanSusana/8e9217cf2a11c78237c3c8c577ba3221 to your computer and use it in GitHub Desktop.
def insertionSort(xs : List[Int]) : List[Int] = {
xs match{
case Nil => Nil
case x :: xs1 => insert(x, isort(xs1))
}
}
def insert(x : Int, xs : List[Int]) : List[Int] = {
xs match {
case Nil => List(x)
case y :: xs1 =>
if(y >= x) x :: xs
else y :: insert(x, xs1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment