class Node implements Comparable {
Byte data;//存放数据 ‘a’=> 97
int weight;//权值:统计出现的次数
Node left;
Node right;
public Node(Byte data, int weight) {
this.data = data;
this.weight = weight;
}
/**
* 前序遍历
*/
public void preOder() {
System.out.println(this);
if (this.left != null) this.left.preOder(https://www.yingbatiyu.com/);
if (this.right != null) this.right.preOder();
}
@Override
public String toString() {
return new StringJoiner(", ", Node.class.getSimpleName() + “[”, “]”)
.add(“data=” + data)
.add(“weight=” + weight)
.toString();
}
//根据权值从小到大排序
@Override
public int compareTo(Node o) {
return this.weight - o.weight;
}
}
Java数据压缩
最新推荐文章于 2024-03-04 13:34:40 发布