Skip to content

Instantly share code, notes, and snippets.

@seoh
Created October 12, 2012 12:25
Show Gist options
  • Save seoh/3878964 to your computer and use it in GitHub Desktop.
Save seoh/3878964 to your computer and use it in GitHub Desktop.
print CodeTree of Assignment4 (FPPiS)
def mkString(tree: CodeTree): String = {
def __mkString(tree: CodeTree, depth: Int): String =
List.fill(depth)('\t').mkString + "(" + chars(tree).mkString + ") " + weight(tree) + "\n" +
(tree match {
case Fork(left, right, chars, weight) =>
__mkString(left, depth + 1) + __mkString(right, depth + 1)
case Leaf(chars, weight) =>
""
})
__mkString(tree, 0)
}
@seoh
Copy link
Author

seoh commented Oct 12, 2012

this is not SOLUTION about assignment of FPPiS. this is just utility function to helping solve an assignment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment