Complete the class PrettyPrint2 to produce the below out of the following binary
ID: 3637228 • Letter: C
Question
Complete the class PrettyPrint2 to produce the below out of the following binary trees (spacing is exact)
(a
(b d e)
(c
()
(f
(g () h)
()
)
)
)
(a
(b
d
(e h i)
)
(c
(f j k)
g
)
)
(*
(+
(/ a 2)
b
)
(^ c 3)
)
This prettyPrint() method is essentially a preorder traversal of the tree. First you pretty print the root, then you (recursively) pretty print the left sub tree, then (recursively) pretty print the right sub tree. Consider Four cases: an empty tree a tree of a single node a tree of depth 1 and a tree of depth greater than 1.
I can't seem to get this right, I can get it fairly close but then it'll still be off with a few nodes
Here's what I have at the moment if it's at all useful, though I may be way off:
Complete the class PrettyPrint2 to produce the below out of the following binary trees (spacing is exact) This prettyPrint() method is essentially a preorder traversal of the tree. First you pretty print the root, then you (recursively) pretty print the left sub tree, then (recursively) pretty print the right sub tree. Consider Four cases: an empty tree a tree of a single node a tree of depth 1 and a tree of depth greater than 1. I can't seem to get this right, I can get it fairly close but then it'll still be off with a few nodes Here's what I have at the moment if it's at all useful, though I may be way off: