Last active
January 8, 2016 18:25
-
-
Save Bekbolatov/e08a138249bc241d7368 to your computer and use it in GitHub Desktop.
Merger trait - common functionality of merging networks
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
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