Created
November 28, 2009 09:33
-
-
Save mpen/244459 to your computer and use it in GitHub Desktop.
Scalaでソート List#sort, Sorting.stableSort
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
// List#sort, Sorting.stableSort | |
import scala.collection.mutable | |
import scala.util.Sorting | |
List(1, 3, 2).sort(_ < _) // List(1, 2, 3) | |
val ar = Array(1, 3, 2) | |
Sorting.stableSort(ar) | |
ar // Array(1, 2, 3) | |
Sorting.stableSort(ar, (a: Int, b: Int) => a > b) | |
ar // Array(3, 2, 1) | |
val mm = mutable.Map(1 -> 70, 2 -> 50) | |
val sorted = // sorted: Array((2,50), (1,70)) | |
Sorting.stableSort(mm.toSeq, | |
(a:(Int, Int), b:(Int, Int)) => a._2 < b._2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment