Created
June 2, 2014 19:51
-
-
Save larryv/8e7d036571a4a02bd0ae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def sortCodeTrees[T <: CodeTree](trees: List[T]): List[T] = { | |
val pivot = trees.length / 2 | |
if (pivot == 0) trees | |
else { | |
def merge(xs: List[T], ys: List[T]): List[T] = (xs, ys) match { | |
case (Nil, ys) => ys | |
case (xs, Nil) => xs | |
case (x :: xs1, y :: ys1) => | |
if (weight(x) < weight(y)) x :: merge(xs1, ys) | |
else y :: merge(xs, ys1) | |
} | |
val (front, back) = trees splitAt pivot | |
merge(sortCodeTrees(front), sortCodeTrees(back)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment