APCS/11 Huffman/01_02 Huffman Coding/Huffman.java
Rushil Umaretiya 3fc3554899 initial commit
2020-12-04 22:00:49 -05:00

44 lines
1.7 KiB
Java

// name: date:
import java.util.*;
import java.io.*;
public class Huffman
{
public static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) throws IOException
{
//Prompt for two strings
System.out.print("Encoding using Huffman codes");
System.out.print("\nWhat message? ");
String message = keyboard.nextLine();
System.out.print("\nEnter middle part of filename: ");
String middlePart = keyboard.next();
huffmanize( message, middlePart );
}
public static void huffmanize(String message, String middlePart) throws IOException
{
//Make a frequency table of the letters
//Put each letter-frequency pair into a HuffmanTreeNode. Put each
// node into a priority queue (or a min-heap).
//Use the priority queue of nodes to build the Huffman tree
//Process the string letter-by-letter and search the tree for the
// letter. It's recursive. As you recur, build the path through the tree,
// where going left is 0 and going right is 1.
//System.out.println the binary message
//Write the binary message to the hard drive using the file name ("message." + middlePart + ".txt")
//System.out.println the scheme from the tree--needs a recursive helper method
//Write the scheme to the hard drive using the file name ("scheme." + middlePart + ".txt")
}
}
/*
* This tree node stores two values. Look at TreeNode's API for some help.
* The compareTo method must ensure that the lowest frequency has the highest priority.
*/
class HuffmanTreeNode implements Comparable<HuffmanTreeNode>
{
}