1.哈夫曼树(实现基本的编码解码)
1.模型构造 // 节点类
public static class Node implements Comparable<Node> {
String data;
double weight;
Node leftChild;
Node rightChild;
Node parent;
public boolean isLeftChild() {
return parent != null && this == parent.leftChild;
}
public Node() {
}
public Node(String data, double weight) {
this.data = data;
this.weight = weight;
}
@Override
public String toString() {
return "Node [data=" + data + ", weight=" + weight + "]";
}
//队列排序依据
public int compareTo(Node o) {
return (int) (weight - o.weight);
}
public boolean isLeaf() {
return data.length() == 1;
}
}