Question: Read through the My Java code and create an understanding of it . / / / My Code / / / import java.util. * ;
Read through the My Java code and create an understanding of it
My Code
import java.util.;
public class Huffman
public static void mainString args
String message "Hello world";
Scanner scanner new ScannerSystemin;
while message.equalsIgnoreCasequit
System.out.printlnEnter a message: ;
message scanner.nextLine;
new Huffmanprocessmessage;
System.out.printlnBYE;
scanner.close;
private void processString phrase
System.out.printlnOriginal: phrase;
PriorityQueue priorityQueue new PriorityQueuephraselength;
for int i ; i phrase.length; i
char c phrase.charAti;
priorityQueue.insertc;
while priorityQueuesize
Node n priorityQueue.remove;
Node n priorityQueue.remove;
Node p createParentn n;
priorityQueue.insertp;
Tree huffmanTree new Tree;
huffmanTree.setRootpriorityQueueremove;
String code huffmanTree.encodephrase;
System.out.printlnCoded: code;
String message huffmanTree.decodecode;
System.out.printlnDecoded: message;
private Node createParentNode n Node n
Node nn new Node nfrequency nfrequency;
if nfrequency nfrequency
nnleftChild n;
nnrightChild n;
else
nnleftChild n;
nnrightChild n;
return nn;
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
