Demonstrates the Huffman coding algorithm with sample data. @param args command line arguments (not used)
(String[] args)
| 191 | * @param args command line arguments (not used) |
| 192 | */ |
| 193 | public static void main(String[] args) { |
| 194 | // Sample characters and their frequencies |
| 195 | char[] charArray = {'a', 'b', 'c', 'd', 'e', 'f'}; |
| 196 | int[] charFreq = {5, 9, 12, 13, 16, 45}; |
| 197 | |
| 198 | System.out.println("Characters: a, b, c, d, e, f"); |
| 199 | System.out.println("Frequencies: 5, 9, 12, 13, 16, 45"); |
| 200 | System.out.println("\nHuffman Codes:"); |
| 201 | |
| 202 | // Build Huffman tree |
| 203 | HuffmanNode root = buildHuffmanTree(charArray, charFreq); |
| 204 | |
| 205 | // Generate and print Huffman codes |
| 206 | Map<Character, String> codes = generateCodes(root); |
| 207 | for (Map.Entry<Character, String> entry : codes.entrySet()) { |
| 208 | System.out.println(entry.getKey() + ": " + entry.getValue()); |
| 209 | } |
| 210 | } |
| 211 | } |
nothing calls this directly
no test coverage detected