Created
August 17, 2016 09:24
-
-
Save veve90/8656a4f8725d2430c5ab19b79debec0a to your computer and use it in GitHub Desktop.
LearningScala|week4.7 |Functional Programming Principles in Scala
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
// sorting a list with a custom method of sorting | |
val x = 7::2::5::Nil; | |
val y = 1::2::List(3,4,Nil)::5::Nil; | |
x.size | |
y.size | |
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) | |
} | |
def issort(xs:List[Int]):List[Int] = xs match { | |
case List() => List() | |
case y :: ys => insert(y,issort(ys)) | |
} | |
issort(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment