欢迎来到天天文库
浏览记录
ID:54701087
大小:46.01 KB
页数:6页
时间:2020-04-20
《霍夫曼编码与解码源程序java版.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、首先是一个简单的排序importjava.util.*;publicclassHeap{ArrayListlist=newArrayList();publicHeap(){}publicHeap(E[]objects){for(inti=0;i2、rentIndex=list.size()-1;while(currentIndex>0){if((list.get(currentIndex)).compareTo(list.get(currentIndex-1))<0){Etemp=list.get(currentIndex);list.set(currentIndex,list.get(currentIndex-1));list.set(currentIndex-1,temp);}elsebreak;currentIndex--;}}publicEre3、move()//删除并返回最小的一个数据{if(list.size()==0)returnnull;EreturnObject=list.get(0);for(inti=0;i4、ode{Scannerinput=newScanner(System.in);int[]counts=newint[256];//各个字符的权重StringtransferMsg=newString();//编码后的字符串StringdecipherMsg=newString();///解码后的字符串String[]codes;publicHuffmanCode(){//System.out.println("选择何种权重值?.");useDefaultHuffmanTree();Treetree=get5、HuffmanTree(counts);codes=getCodes(tree.root);System.out.print("输出从a开始的字符的各个编码:");for(inti=0;i6、ngtext=input.nextLine();//待编码的字符串System.out.print("输出输入字符串的huffman编码");for(inti=0;i7、oiddecipherTMsg(){//解码//TODOAuto-generatedmethodstubintj=0;for(inti=0;i8、+){if(substring.equals(codes[i])){decipherMsg+=(char)i;returntrue;}}returnfalse;}privatevoiduseDefaultHuffmanTree()//各个字符的权重{counts['a']=1859;counts['b']=642;counts['c']=218;counts['d']=317;counts['e']
2、rentIndex=list.size()-1;while(currentIndex>0){if((list.get(currentIndex)).compareTo(list.get(currentIndex-1))<0){Etemp=list.get(currentIndex);list.set(currentIndex,list.get(currentIndex-1));list.set(currentIndex-1,temp);}elsebreak;currentIndex--;}}publicEre
3、move()//删除并返回最小的一个数据{if(list.size()==0)returnnull;EreturnObject=list.get(0);for(inti=0;i4、ode{Scannerinput=newScanner(System.in);int[]counts=newint[256];//各个字符的权重StringtransferMsg=newString();//编码后的字符串StringdecipherMsg=newString();///解码后的字符串String[]codes;publicHuffmanCode(){//System.out.println("选择何种权重值?.");useDefaultHuffmanTree();Treetree=get5、HuffmanTree(counts);codes=getCodes(tree.root);System.out.print("输出从a开始的字符的各个编码:");for(inti=0;i6、ngtext=input.nextLine();//待编码的字符串System.out.print("输出输入字符串的huffman编码");for(inti=0;i7、oiddecipherTMsg(){//解码//TODOAuto-generatedmethodstubintj=0;for(inti=0;i8、+){if(substring.equals(codes[i])){decipherMsg+=(char)i;returntrue;}}returnfalse;}privatevoiduseDefaultHuffmanTree()//各个字符的权重{counts['a']=1859;counts['b']=642;counts['c']=218;counts['d']=317;counts['e']
4、ode{Scannerinput=newScanner(System.in);int[]counts=newint[256];//各个字符的权重StringtransferMsg=newString();//编码后的字符串StringdecipherMsg=newString();///解码后的字符串String[]codes;publicHuffmanCode(){//System.out.println("选择何种权重值?.");useDefaultHuffmanTree();Treetree=get
5、HuffmanTree(counts);codes=getCodes(tree.root);System.out.print("输出从a开始的字符的各个编码:");for(inti=0;i6、ngtext=input.nextLine();//待编码的字符串System.out.print("输出输入字符串的huffman编码");for(inti=0;i7、oiddecipherTMsg(){//解码//TODOAuto-generatedmethodstubintj=0;for(inti=0;i8、+){if(substring.equals(codes[i])){decipherMsg+=(char)i;returntrue;}}returnfalse;}privatevoiduseDefaultHuffmanTree()//各个字符的权重{counts['a']=1859;counts['b']=642;counts['c']=218;counts['d']=317;counts['e']
6、ngtext=input.nextLine();//待编码的字符串System.out.print("输出输入字符串的huffman编码");for(inti=0;i7、oiddecipherTMsg(){//解码//TODOAuto-generatedmethodstubintj=0;for(inti=0;i8、+){if(substring.equals(codes[i])){decipherMsg+=(char)i;returntrue;}}returnfalse;}privatevoiduseDefaultHuffmanTree()//各个字符的权重{counts['a']=1859;counts['b']=642;counts['c']=218;counts['d']=317;counts['e']
7、oiddecipherTMsg(){//解码//TODOAuto-generatedmethodstubintj=0;for(inti=0;i8、+){if(substring.equals(codes[i])){decipherMsg+=(char)i;returntrue;}}returnfalse;}privatevoiduseDefaultHuffmanTree()//各个字符的权重{counts['a']=1859;counts['b']=642;counts['c']=218;counts['d']=317;counts['e']
8、+){if(substring.equals(codes[i])){decipherMsg+=(char)i;returntrue;}}returnfalse;}privatevoiduseDefaultHuffmanTree()//各个字符的权重{counts['a']=1859;counts['b']=642;counts['c']=218;counts['d']=317;counts['e']
此文档下载收益归作者所有