Skip to content

Instantly share code, notes, and snippets.

@teivah
Last active October 30, 2018 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teivah/00b66e1edee405a954fd162e0fb15a97 to your computer and use it in GitHub Desktop.
Save teivah/00b66e1edee405a954fd162e0fb15a97 to your computer and use it in GitHub Desktop.
def mergesort1(array: Array[Int]): Unit = {
val helper = new Array[Int](array.length)
mergesort2(array, helper, 0, array.length - 1)
}
private def mergesort2(array: Array[Int], helper: Array[Int], low: Int, high: Int): Unit = {
if (low < high) {
val middle = (low + high) / 2
mergesort2(array, helper, low, middle)
mergesort2(array, helper, middle + 1, high)
merge(array, helper, low, middle, high)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment