A ternary tree is like a binary tree, except each node may have up to three successors. Write a TNode class that can be used to represent a ternary tree. Define a notion of preorder and postorder traversal for ternary trees, and write methods void postorder(TNode tree) and void preorder(TNode tree) that implements your notion of those traversals.
What will be an ideal response?
```
class TNode
{
TNode left, middle, right;
String value;
}
void postOrder(TNode tree)
{
if (tree != null)
{
postOrder(tree.left);
postOrder(tree.middle);
postOrder(tree.right);
System.out.print(tree.value + " ");
}
}
void preOrder(TNode tree)
{
if (tree != null)
{
System.out.print(tree.value + " ");
preOrder(tree.left);
preOrder(tree.middle);
preOrder(tree.right);
}
}
```
You might also like to view...
By default, Apache is configured with no default host and no virtual host.
Answer the following statement true (T) or false (F)
When you perform a(n) ____, you must use a Project 2010 file that was used during the actual project, that is, a project file that has actual and baseline values.
A. CPI B. EVA C. CV D. VAC