September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,11 +1,6 @@
|
|||
def sort(xs: List[Int]): List[Int] = {
|
||||
xs match {
|
||||
case Nil => Nil
|
||||
case x :: xx => {
|
||||
// Arbitrarily partition list in two
|
||||
val (lo, hi) = xx.partition(_ < x)
|
||||
// Sort each half
|
||||
sort(lo) ++ (x :: sort(hi))
|
||||
}
|
||||
}
|
||||
def sort(xs: List[Int]): List[Int] = xs match {
|
||||
case Nil => Nil
|
||||
case head :: tail =>
|
||||
val (less, notLess) = tail.partition(_ < head) // Arbitrarily partition list in two
|
||||
sort(less) ++ (head :: sort(notLess)) // Sort each half
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
def sort[T](xs: List[T], lessThan: (T, T) => Boolean): List[T] = {
|
||||
xs match {
|
||||
case Nil => Nil
|
||||
case x :: xx => {
|
||||
val (lo, hi) = xx.partition(lessThan(_, x))
|
||||
sort(lo, lessThan) ++ (x :: sort(hi, lessThan))
|
||||
}
|
||||
}
|
||||
def sort[T](xs: List[T], lessThan: (T, T) => Boolean): List[T] = xs match {
|
||||
case Nil => Nil
|
||||
case x :: xx =>
|
||||
val (lo, hi) = xx.partition(lessThan(_, x))
|
||||
sort(lo, lessThan) ++ (x :: sort(hi, lessThan))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
def sort[T](xs: List[T])(implicit ord: Ordering[T]): List[T] = {
|
||||
xs match {
|
||||
case Nil => Nil
|
||||
case x :: xx => {
|
||||
val (lo, hi) = xx.partition(ord.lt(_, x))
|
||||
sort[T](lo) ++ (x :: sort[T](hi))
|
||||
}
|
||||
}
|
||||
def sort[T](xs: List[T])(implicit ord: Ordering[T]): List[T] = xs match {
|
||||
case Nil => Nil
|
||||
case x :: xx =>
|
||||
val (lo, hi) = xx.partition(ord.lt(_, x))
|
||||
sort[T](lo) ++ (x :: sort[T](hi))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
def sort[T <: Ordered[T]](xs: List[T]): List[T] = {
|
||||
xs match {
|
||||
case Nil => Nil
|
||||
case x :: xx => {
|
||||
val (lo, hi) = xx.partition(_ < x)
|
||||
sort(lo) ++ (x :: sort(hi))
|
||||
}
|
||||
}
|
||||
def sort[T <: Ordered[T]](xs: List[T]): List[T] = xs match {
|
||||
case Nil => Nil
|
||||
case x :: xx =>
|
||||
val (lo, hi) = xx.partition(_ < x)
|
||||
sort(lo) ++ (x :: sort(hi))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue