Science 20182325 Yuan No. Source "Object-oriented programming and data structures" Huffman coding Practice
(1) Prepare a 26 letters of the English file contains (or may not contain punctuation, etc.), the probability of each character's statistics
- English documents prepared in advance
- A write stream file reading
- Create an array to store the number of letters appear. Appeared on the increment. Instead of using the number of probability.
(2) configured Huffman
- Establishing List
nodes = new ArrayList (); With 26 letters and the number of characters stored as data.
- The number of characters to sort, the two smallest removed from the array, and the synthesis of a new node array.
The array of the last node as the root node.
(3) the English documents encoded file, the output of a coding
Traversing the Huffman tree, into the left sub-tree coding add "0" into the right sub-tree coding "1"
Success coding leaf node.
By letter by letter flow determination, after the code "01" who create a new file.
(4) decoding the encoded file, outputting a decoded file
- A queue way, each element added to a determination, whether there is a corresponding sequence. If there is a character output.
- Create a new file.