1. 用java实现哈夫曼编码
只要自己再加个类Tree就可以了。
代码如下:
public class Tree {
double lChild, rChild, parent;
public Tree (double lChild, double rChild, double parent) {
this.lChild = lChild;
this.rChild = rChild;
this.parent = parent;
}
public double getLchild() {
return lChild;
}
public void setLchild(double lChild) {
this.lChild = lChild;
}
public double getRchild() {
return rChild;
}
public void setRchild(double rChild) {
this.rChild = rChild;
}
public double getParents() {
return parent;
}
public void setParents(double root) {
this.parent = root;
}
}
2. 哈夫曼编码与译码 java
class HaffmanNode //哈夫曼树的结点类
{
int weight; //权值
int parent,left,right; //父母结点和左右孩子下标
public HaffmanNode(int weight)
{
this.weight = weight;
this.parent=-1;
this.left=-1;
this.right=-1;
}
public HaffmanNode()
{
this(0);
}
public String toString()
{
return this.weight+", "+this.parent+", "+this.left+", "+this.right;
}
return code;
}
public static void main(String[] args)
{
int[] weight={5,29,7,8,14,23,3,11}; //指定权值集合
HaffmanTree htree = new HaffmanTree(weight);
System.out.println("哈夫曼树的结点数组:\n"+htree.toString());
String[] code = htree.haffmanCode();
System.out.println("哈夫曼编码:");
for (int i=0; i<code.length; i++)
System.out.println(code[i]);
}
}
3. 哈夫曼编码译码器 java
建议: 用类似的方法,可以将某一学科的总分统计出来,并填入第48行相应的单元格中。
你好,由于内容比较多,先概述一下先。如图所示,为我写的一个压缩软件,原理是利用哈弗曼算法实现的。我将资料整理好稍后就发到你邮箱,但在这里简要说明一下代码。
请看我的空间
http://hi..com/%D2%B6%BF%C6%C1%BC/blog
中的文章共5篇(太长了)
http://hi..com/%D2%B6%BF%C6%C1%BC/blog/item/93c35517bb528146f2de32fd.html
1.HuffmanTextEncoder类完成压缩功能,可直接运行,压缩测试用文本文件。
2.HuffmanTextDecoder类完成解压缩功能,可直接运行,解压缩压缩后的文本文件。
3.BitReader,工具类,实现对BufferedInputStream的按位读取。
4.BitWriter,工具类,实现按位写入的功能。该类来自网络。
5.MinHeap<T>,模板工具类,实现了一个最小堆。生成Huffman树时使用。
5. 哈夫曼树编码的应用(Java语言)
1)编写函数实现选择parent为0且权值最小的两个根结点的算法
2)编写函数实现统计字符串中字符的种类以及各类字符的个数。
3)编写函数构造赫夫曼树。
4)编写函数实现由赫夫曼树求赫夫曼编码表。
5)编写函数实现将正文转换为相应的编码文件。
6)编写函数实现将编码文件进行译码。
7)编写主控函数,完成本实验的功能。