import java.io.*;
public class Huffumancode {
/**
* @param args
*/
static float sum=0;
static String s;
public static void main(String[] args) {
// TODO Auto-generated method stub
new Huffumancode().run();
}
public void run()
{
try
{
FileReader fr=new FileReader("WordAndFreq.txt");
BufferedReader br=new BufferedReader(fr);
String s=null;
Node []A=new Node[24686];
A[0]=new Node();
A[0].freq=24685;
int i=1;
String []st=new String [2];
while((s=br.readLine())!=null)
{
st=s.split("\\s");
A[i]=new Node();
A[i].data=st[0];
A[i].freq=Integer.parseInt(st[1]);
i++;
}
System.out.println(A[24685].data +A[24685].freq);
heap_sort(A);
A[0].freq=24685;
build_huffmantree(A);
System.out.println("A[1]ede pin ldu"+A[1].freq);
FileWriter fw=new FileWriter("output.txt");
BufferedWriter bw=new BufferedWriter(fw);
preorder(A[1],bw);
bw.flush();
float average=sum/3330999;
String s1="the average length of the code is :".concat(Float.toString(average));
bw.write(s1);
bw.close();
System.out.println(average);
}
catch(Exception e)
{
System.out.println(e);
}
}