「java霍夫曼编码」java哈夫曼编码
今天给各位分享java霍夫曼编码的知识,其中也会对java哈夫曼编码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
哈夫曼编码译码器 java
建议: 用类似的方法,可以将某一学科的总分统计出来,并填入第48行相应的单元格中。
哈夫曼树编码的应用(Java语言)
1)编写函数实现选择parent为0且权值最小的两个根结点的算法
2)编写函数实现统计字符串中字符的种类以及各类字符的个数。
3)编写函数构造赫夫曼树。
4)编写函数实现由赫夫曼树求赫夫曼编码表。
5)编写函数实现将正文转换为相应的编码文件。
6)编写函数实现将编码文件进行译码。
7)编写主控函数,完成本实验的功能。
用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;
}
}
哈夫曼编码与译码 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; icode.length; i++)
System.out.println(code[i]);
}
}
java霍夫曼编码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java哈夫曼编码、java霍夫曼编码的信息别忘了在本站进行查找喔。