Skip to content

Instantly share code, notes, and snippets.

@veve90
Created August 17, 2016 09:24
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 veve90/8656a4f8725d2430c5ab19b79debec0a to your computer and use it in GitHub Desktop.
Save veve90/8656a4f8725d2430c5ab19b79debec0a to your computer and use it in GitHub Desktop.
LearningScala|week4.7 |Functional Programming Principles in Scala
// 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