Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Assignment4;
- import java.util.*;
- import java.io.*;
- public class HuffmanTree
- {
- HuffmanNode root;
- //
- // Sets this.root to huff
- public HuffmanTree(HuffmanNode huff) {
- this.root = huff;
- }
- public void printLegend() {
- printLegend(root, "");
- }
- private void printLegend(HuffmanNode t, String s){
- String x = "";
- if(t.letter.length() > 1){
- printLegend(t.left, x + "0");
- printLegend(t.right, x + "1");
- }
- else
- System.out.println(t.letter + " = " + x);
- }
- public static BinaryHeap<HuffmanNode> fileToHeap(String filename) {
- BinaryHeap<HuffmanNode> binaryHeap = new BinaryHeap<HuffmanNode>();
- /*try{
- FileReader fr = new FileReader("huff.txt");
- //BufferedReader br = new BufferedReader(fr);
- //String line = br.readLine();
- //System.out.println(line);
- }
- catch(Exception e){System.out.println("fail ");}*/
- return binaryHeap;
- }
- public static HuffmanTree createFromHeap(BinaryHeap<HuffmanNode> b) {
- return new HuffmanTree(new HuffmanNode("", null));
- }
- public static void main(String args[]){
- try{
- FileInputStream file = new FileInputStream(".");
- System.out.println("success ");
- }
- catch(Exception e){System.out.println("damn ");}
- Scanner sc = new Scanner(System.in);
- System.out.println("Type file name ");
- String name = sc.nextLine();
- System.out.println("this is name " + name);
- BinaryHeap<HuffmanNode> bheap = fileToHeap(name);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement