1 Star 0 Fork 0

besti1923/JAVA

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
HaffNode.java 989 Bytes
一键复制 编辑 原始数据 按行查看 历史
yifei 提交于 5年前 . bianma
package text.java;
public class HaffNode<T> {
char data;
int weight;
HaffNode father, leftChild, rightChild;
public HaffNode(char s) {
this.data = s;
weight = 0;
father = null;
leftChild = null;
rightChild = null;
}
public HaffNode(HaffNode a, HaffNode b) {
this.data = ' ';
weight = a.weight + b.weight;
father = null;
leftChild = a;
rightChild = b;
a.father = this;
b.father = this;
}
public String code(HaffNode root) {//逆向编码
String a = "";
if (father != null) {
if (this == father.leftChild) a += "0" + father.code(root);
else a += "1" + father.code(root);
}
return a;
}
public String recode(HaffNode root) {
String a = code(root);
String b = "";
for (int i = a.length() - 1; i >= 0; i--) {
b += a.charAt(i);
}
return b;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/besti1923/java.git
git@gitee.com:besti1923/java.git
besti1923
java
JAVA
master

搜索帮助