all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,7 @@
|
|||
def quicksortInt(coll: List[Int]): List[Int] =
|
||||
if (coll.isEmpty) {
|
||||
coll
|
||||
} else {
|
||||
val (smaller, bigger) = coll.tail partition (_ < coll.head)
|
||||
quicksortInt(smaller) ::: coll.head :: quicksortInt(bigger)
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
def quicksortFunc[T](coll: List[T], lessThan: (T, T) => Boolean): List[T] =
|
||||
if (coll.isEmpty) {
|
||||
coll
|
||||
} else {
|
||||
val (smaller, bigger) = coll.tail partition (lessThan(_, coll.head))
|
||||
quicksortFunc(smaller, lessThan) ::: coll.head :: quicksortFunc(bigger, lessThan)
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
def quicksortOrd[T <% Ordered[T]](coll: List[T]): List[T] =
|
||||
if (coll.isEmpty) {
|
||||
coll
|
||||
} else {
|
||||
val (smaller, bigger) = coll.tail partition (_ < coll.head)
|
||||
quicksortOrd(smaller) ::: coll.head :: quicksortOrd(bigger)
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
def quicksort
|
||||
[T, CC[X] <: Seq[X] with SeqLike[X, CC[X]]] // My type parameters
|
||||
(coll: CC[T]) // My explicit parameter
|
||||
(implicit o: T => Ordered[T], cbf: CanBuildFrom[CC[T], T, CC[T]]) // My implicit parameters
|
||||
: CC[T] = // My return type
|
||||
if (coll.isEmpty) {
|
||||
coll
|
||||
} else {
|
||||
val (smaller, bigger) = coll.tail partition (_ < coll.head)
|
||||
quicksort(smaller) ++ (coll.head +: quicksort(bigger))
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
def quicksortInt(list: List[Int]): List[Int] = list match {
|
||||
case head :: tail =>
|
||||
val (smaller, bigger) = tail partition (_ < head)
|
||||
quicksortInt(smaller) ::: head :: quicksortInt(bigger)
|
||||
case list => list
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue