Due: Tuesday 4/9 10:00am

Submission name: w17_traversal

For this, you will need the TreeNode and Tree classes, which you can get here: https://github.com/nextcs-dw/dwsource/tree/main/TreeBasic

Make the following modifications to your Tree class:

  • Change makeTree so that left and right subtrees are not always made.
    • This means that makeTree will no longer definitely make trees with a particular height. That is ok.
    • You can decided how likely your program is to generate a subtree. If you’re going to use the same percentage each time, I suggest something at least as large as 60%, otherwise you won’t get very interesting trees. If you want to try something fancier, you could tie the percentage to the current level, where levels closer to the root are more likely to have subtrees than lower levels.
  • Add three methods to the Tree class. preOrder, inOrder, and postOrder. Each should return a String which is the result of doing a pre, in, and post order traversal of a tree. In your driver file, display the traversal results on the screen.

a17-tree