Skip to content

Instantly share code, notes, and snippets.

@Bekbolatov
Last active January 8, 2016 18:25
Show Gist options
  • Save Bekbolatov/e08a138249bc241d7368 to your computer and use it in GitHub Desktop.
Save Bekbolatov/e08a138249bc241d7368 to your computer and use it in GitHub Desktop.
Merger trait - common functionality of merging networks
trait Merger {
def merge(xs: Seq[Int], ys: Seq[Int]): Seq[Int]
}
trait MergeSorting {
self: Merger =>
def sort(xs: Seq[Int]): Seq[Int] = {
if (xs.size < 2) {
xs
} else {
val (lefts, rights) = xs.splitAt(xs.size / 2)
merge(sort(lefts), sort(rights))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment