Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. package Assignment4;
  2.  
  3. import java.util.*;
  4. import java.io.*;
  5.  
  6. public class HuffmanTree
  7. {
  8. HuffmanNode root;
  9.  
  10. //
  11. // Sets this.root to huff
  12.  
  13. public HuffmanTree(HuffmanNode huff) {
  14. this.root = huff;
  15.  
  16. }
  17.  
  18. public void printLegend() {
  19. printLegend(root, "");
  20. }
  21. private void printLegend(HuffmanNode t, String s){
  22. String x = "";
  23. if(t.letter.length() > 1){
  24. printLegend(t.left, x + "0");
  25. printLegend(t.right, x + "1");
  26. }
  27. else
  28. System.out.println(t.letter + " = " + x);
  29. }
  30.  
  31.  
  32. public static BinaryHeap<HuffmanNode> fileToHeap(String filename) {
  33. BinaryHeap<HuffmanNode> binaryHeap = new BinaryHeap<HuffmanNode>();
  34. /*try{
  35. FileReader fr = new FileReader("huff.txt");
  36. //BufferedReader br = new BufferedReader(fr);
  37. //String line = br.readLine();
  38. //System.out.println(line);
  39. }
  40. catch(Exception e){System.out.println("fail ");}*/
  41.  
  42.  
  43. return binaryHeap;
  44. }
  45.  
  46. public static HuffmanTree createFromHeap(BinaryHeap<HuffmanNode> b) {
  47.  
  48.  
  49. return new HuffmanTree(new HuffmanNode("", null));
  50. }
  51.  
  52.  
  53. public static void main(String args[]){
  54.  
  55. try{
  56. FileInputStream file = new FileInputStream(".");
  57. System.out.println("success ");
  58. }
  59. catch(Exception e){System.out.println("damn ");}
  60.  
  61.  
  62. Scanner sc = new Scanner(System.in);
  63. System.out.println("Type file name ");
  64. String name = sc.nextLine();
  65. System.out.println("this is name " + name);
  66. BinaryHeap<HuffmanNode> bheap = fileToHeap(name);
  67.  
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement