Skip to content

Instantly share code, notes, and snippets.

@mpen
Created November 28, 2009 09:33
Show Gist options
  • Save mpen/244459 to your computer and use it in GitHub Desktop.
Save mpen/244459 to your computer and use it in GitHub Desktop.
Scalaでソート List#sort, Sorting.stableSort
// 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