HuffmanEncoder - Compilation javac HuffmanEncoder.java...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/************************************************************************* * Compilation: javac HuffmanEncoder.java In.java * Execution: java HuffmanEncoder.java < input.txt * * Read in a list of 8-bit extended ASCII characters and output * their Huffman encoding. * * * % java HuffmanEncoder < abra.txt * * *************************************************************************/ public class HuffmanEncoder { final static int SYMBOLS = 256; // alphabet size final static char SENTINEL = '*'; // character assumed not to be in input private HuffmanTree tree; // root of tree private String[] lookup; // lookup[c] = encoding of symbol c // Huffman tree private class HuffmanTree implements Comparable { char c; int freq; HuffmanTree left, right; HuffmanTree(char c, int freq, HuffmanTree left, HuffmanTree right) { this.c = c; this.freq = freq; this.left = left; this.right = right; } // preorder traversal void preorder() { System.out.print(c); left.preorder();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 2

HuffmanEncoder - Compilation javac HuffmanEncoder.java...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online