求解哈夫曼编码Java实现,用Java实现哈夫曼编码解决方法
當前位置:我的異常網? J2SE???用Java實現哈夫曼編碼解決方法
用Java實現哈夫曼編碼解決方法
www.myexceptions.net??網友分享于:2013-01-08??瀏覽:13次
用Java實現哈夫曼編碼
我有一個程序 但是運行結果不對 而且 也沒有界面設計
請各位高手幫忙修改下 用JAVA實現 要有界面設計 謝謝
import java.io.*;
public class Huffumancode {
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);
}
}
public void min_Heapify( Node []A, int i)
{
int l=2*i;
int r=2*i+1;
int small;
if(l<=A[0].freq&&A[l].freq
small=l;
else small=i;
if (r<=A[0].freq&&A[r].freq
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的求解哈夫曼编码Java实现,用Java实现哈夫曼编码解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: hdu 3652 B-number 数位
- 下一篇: 操作系统常用英文
