Originally Posted by
Chewybakas
...I have no idea how to do.
The exam is from a course on algorithms or data structures or some such thing. The specific assignment is expressed as comments in the code:
.
.
.
//FILL THIS IN: //<--- This is line 47 of the code you posted
//MAKE THE FOREST OF TREES AND ADD THEM TO THE PQ
//create a new Tree
//set the cumulative frequency of that Tree
//insert the letter as the root node
//add the Tree into the PQ
.
.
.
//FILL THIS IN: // <--- Line 66
//IMPLEMENT THE HUFFMAN ALGORITHM
//when you're making the new combined tree, don't forget to assign a default root node (or else you'll get a null pointer exception)
//if you like, to check if everything is working so far, try printing out the letter of the roots of the two trees you're combining
.
.
.
//FILL THIS IN: <--- Line 78
//get all the codes for the letters and print them out
//call the getCode() method on the HuffmanTree Tree object for each letter in the sentence
//print out all the info
If a person has taken the course and doesn't have a clue as to where to start the "FILL THIS IN" stuff, well, maybe it is time to go back through class notes or textbook or whatever other material was presented. Maybe students were even given references to additional material for individual study.
If a person has not taken the course and has no clue as to how to do Huffman coding, one might get a textbook on algorithms or find something on-line that would help. For example, the Fourth Edition of the excellent and ubiquitous "Algorithms" book by Sedgewick even uses Java for its example code. A lot of the program material is available (legally and free) here:
Algirithms, 4th Edition
Anyhow...
Just having some Java code that implements and illustrates some of the material might not be enough to finish the exam and/or pass the course, but I think it might be a starting point for study...
Cheers!
Z