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...
LINQ’s Order By clause supports values of any type that implements the interface__________, such as the primitive numeric types and String.
a) ICompare b) ICompareTo c) IComparable d) ISort
In writing VBA procedures, comments are displayed in green and are preceded by an ________
Fill in the blank(s) with correct word
In Outlook Express, each e-mail account is given a Microsoft ________, which is a unique hexadecimal representation for that account
Fill in the blank(s) with correct word
When working from home, a pharmaceutical sales representative likes to use an external mouse, keyboard, and display. Which Windows Control Panel could be used to use just the external monitor when the laptop lid is closed?
A) Action Center B) Device Manager C) Windows Firewall D) Power Options