Last active
April 15, 2019 13:42
-
-
Save alirezameskin/498c0d4b88e3f57cb8244a734873dbad to your computer and use it in GitHub Desktop.
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 getLargest[T <% Ordered[T]](data: List[T]): (T, List[T]) = | |
data match { | |
case head :: Nil => (head, Nil) | |
case head :: tail => | |
val (large, remaining) = getLargest(tail) | |
if (large > head) | |
(large, head :: remaining) | |
else | |
(head, large :: remaining) | |
} | |
def bubbleSort[T <% Ordered[T]](data: List[T]): List[T] = | |
data match { | |
case Nil => Nil | |
case _ => | |
val (greatest, tail) = getLargest(data) | |
bubbleSort(tail) ::: List(greatest) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment