-
-
Save claussni/4296669 to your computer and use it in GitHub Desktop.
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
abstract class Tree | |
case class Leaf(value: String) extends Tree | |
case class Branch(left: Tree, right: Tree) extends Tree | |
def walk(t: Tree): Unit = | |
t match { | |
case Branch(Stub, _) => println("branch-with-stub-on-the-left") | |
case Branch(left, right) => { | |
println("\nbranch-leaf") | |
walk(left) | |
walk(right) | |
} | |
case Leaf(v) => printf("\tleaf: %s\t", v) | |
} | |
walk(Branch( | |
Leaf("A"), Branch( | |
Branch(Leaf("D"),Leaf("B")), Leaf("C")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment