Q.When run the program should ask for an input ﬁle containing integer keys to be added to the

search tree. The ﬁle will contain one key per line. Add these keys in the order given in the ﬁle to

the search tree. Then print the entire tree using preorder traversal i.e., root, left-child, right-child.

The output must be indented properly to show the appropriate levels.

For example, if the input keys are 4, 3, 7, 8, 6. The output should look like this

4

<2 spaces>3

<2 spaces>7

<3 spaces>6

<3 spaces>8

I have made the tree. How do I go about printing it as shown above?? ANY help would highly be appreciated.

search tree. The ﬁle will contain one key per line. Add these keys in the order given in the ﬁle to

the search tree. Then print the entire tree using preorder traversal i.e., root, left-child, right-child.

The output must be indented properly to show the appropriate levels.

For example, if the input keys are 4, 3, 7, 8, 6. The output should look like this

4

<2 spaces>3

<2 spaces>7

<3 spaces>6

<3 spaces>8

I have made the tree. How do I go about printing it as shown above?? ANY help would highly be appreciated.

Last edited: