
正文
哈夫曼树代码java 哈夫曼树编码的实现
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
哈夫曼编码与译码 java
class HaffmanNode //哈夫曼树哈夫曼树代码java的结点类
{
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("哈夫曼树哈夫曼树代码java的结点数组:\n"+htree.toString());
String[] code = htree.haffmanCode();
System.out.println("哈夫曼编码:");
for (int i=0; icode.length; i++)
System.out.println(code[i]);
}
}
相关问答
Q1: 哈夫曼树编码的应用(Java语言)
1)编写函数实现选择parent为0且权值最小的两个根结点的算法
2)编写函数实现统计字符串中字符的种类以及各类字符的个数。
3)编写函数构造赫夫曼树。
4)编写函数实现由赫夫曼树求赫夫曼编码表。
5)编写函数实现将正文转换为相应的编码文件。
6)编写函数实现将编码文件进行译码。
7)编写主控函数,完成本实验的功能。
Q2: 我用java构建哈夫曼树的时候报了空指针,代码如下
System.out.println("please input the second letter!");
char ch2 = tw.getChar();
if(ch2 == 'U') {System.out.println("Tuesday"); }
else if(ch2 == 'H') {System.out.println("Thursday"); }
关于哈夫曼树代码java和哈夫曼树编码的实现的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。








