Question: JAVA PLEASE 1 . Store each letter of the alphabet in a binary tree. The root node stores no letter. 2 . Travel to the
JAVA PLEASE
Store each letter of the alphabet in a binary tree. The root node stores no letter.
Travel to the left represents a dot and travel to the right represents a dash. Build the tree using the
Morse code to travel left or right and then insert the letter.
aInitially the tree has a root node with no data.
bRead the first line of the text file: e o Letter e is represented by a single dot. Travel begins from the
root. Dot means travel left. There is no left child encountered so make a node and insert letter
cRead the next line of the text file: t
Letter t is represented by a single dash. Travel begins from the
root. Dash means travel right. There is no right child so make a node and insert letter t
dRead the next line of the text file: i oo Letter i is represented by a two dots. Dot means travel left. The
first left goes to node eThere is no left child of e so make a node and insert letter i
eRepeat this process until all letters have been processed from the file and inserted into the tree.
The program will also use an array to store the code for each letter. Store the code for the letter at the
index using its ASCII code to determine position. The ASCII sequence for az begins at code Morse code for a is stored in index Morse code for bis stored in index etc. You can compute thearray index exfrom the letter exaby subtracting from the letter.
char letter a;
int index intletter ; intareturns and subtract returns
code for letter a ois stored at index
letter b;
index intletter ; intbreturns and subtract returns
code for letter b ooois stored at index Report the preorder traversal of the tree. If your answer does not match the output shown, your tree is not built correctly so do not continue until this part is done. This code should write the recursive method shown.
display a preorder traversal of the tree
public static void preOrderDisplay TreeNode node
After the two data structures are filled, run an interactive program where the user enters an English
word in lower case. Report the Morse code equivalent using the array with character to separate codes, and then decode the Morse code string back to English using the tree.
Use this code: TreeNode models a node for a binary tree
package binarytree;
public class TreeNode
private T element; data field
private TreeNode left; reference to left
child node
private TreeNode right; reference to right
child node
public TreeNode POST: empty
tree node
element null;
left right null;
public TreeNode T elem POST: tree node with
element set
element elem;
left right null;
public TreeNode T elem, TreeNode left, TreeNode right
element elem; POST: tree node
with all fields set
this.left left;
this.right right;
accessors and modifiers
public T getElement return element;
public void setElementT element this.element element;
public TreeNode getLeft return left;
public void setLeftTreeNode left this.left left;
public TreeNode getRight return right;
public void setRightTreeNode right this.right right;
public boolean isLeaf POST: return true if node is a leaf node
return left null && right null;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
