Created
May 4, 2013 17:43
-
-
Save karimamer/5518198 to your computer and use it in GitHub Desktop.
insertion sort
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
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