Skip to content

Instantly share code, notes, and snippets.

@karimamer
Created May 4, 2013 17:43
Show Gist options
  • Save karimamer/5518198 to your computer and use it in GitHub Desktop.
Save karimamer/5518198 to your computer and use it in GitHub Desktop.
insertion sort
def Isort(x:List[Int]):List[Int]= x match {
case List() => List()
case y :: ys => insert (y , Isort(ys))
}
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 )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment