Introduction

Create a ternary tree of characters, and print all strings which can be made by following branches of that tree.

This will prepare you for Q4. Be sure to place the practice quiz in your quizspace so that you may access it during the quiz.

Getting Started

Create a project called PQ4 in Eclipse and import PQ4-starter.jar.

Your directory should now look like this:

PQ4/
└── src
    ├── Node.java
    └── PQ4.java
Instructions
  1. Go to the Node class and finish the Node data structure:

    • The Node class is used to build ternary trees. A ternary tree is very similar to a binary tree, except that it can have up to 3 children: left, center, and right.

The rest of the code will be in PQ4.java.

  1. Implement the buildTree() method

The image below shows the tree, with leaf nodes shown as circles:

Ternary Tree Diagram
  1. Implement the printTree() method

Testing and Additional Notes

The total code to be written, based on the instructor solution (not including brackets, comments and empty lines):

Here is the expected output from the test code provided:

Letters: [c, a, o, u, d, n, r, g, p, w, b, r, t]
Words:
cad
can
car
cog
cop
cow
cub
cur
cut

HINT: You can change the code in your main method! This won’t effect our testing.

If you have time for additional testing:

Submission

Once complete, submit PQ4.java to Checkin.