





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The implementation of a Morse Code tree in Java using a TreeNode class. The tree is constructed by inserting Morse codes of characters and traversing the tree to print Morse codes of strings in pre-order and post-order. The document also includes methods for height calculation and insertion of nodes.
Typology: Summaries
1 / 9
This page cannot be seen from the preview
Don't miss anything!






package tree; import java.util.*; public class TreeNode
public void setLeft(TreeNode
return "o-oo"; case 'm': return "--"; case 'n': return "- oo"; case 'o': return "---"; case 'p': return "o--o"; case 'q': return "--o-"; case 'r': return "o-o"; case 's': return "o o o"; case 't': return "-"; case 'u': return "o o-"; case 'v': return "oooo"; case 'w': return "o--"; case 'x': return "-oo-"; case 'y': return "-o--"; case 'z': return "--oo";
case '1': return "o----"; case '2': return "oo---"; case '3': return "ooo--"; case '4': return "oooo-"; case '5': return "ooooo"; case '6': return "-oooo"; case '7': return "--ooo"; case '8': return "--oo"; case '9': return "----o"; case '0': return "-----"; default: return ""; } } public void postorder(TreeNode
public void insert(T element) { TreeNode
if (this.getLeft() == null){ this.setLeft(insertTarget); } else if (this.getRight() == null){ this.setRight(insertTarget); } else{ if (this.getLeft().height() <= this.getRight().height()){ this.getLeft().insert(element); } else if (this.getLeft().height() > this.getRight().height()){ this.getRight().insert(element); } } } } public void insertLeft(T element){ if (this.getLeft() == null){ this.setLeft(new TreeNode