实现哈夫曼树(最优二叉树)
public class HuffmanTree { //节点 public static class Node<E> { E data; //数据 int weight; //权重 Node leftChild; //左子节点 Node rightChild;//右子节点 public Node(E data, int weight) { super(); this.data = data; this.weight = weight; } public String toString() { return "Node[" + weight + ",data=" + data + "]"; } } public static void main(String[] args) { List<Node> nodes = new ArrayList<Node>(); //把节点加入至list中 nodes.add(new Node("a", 10)); nodes.add(new Node("b", 15)); nodes.add(new Node("c", 12)); nodes.add(new Node("d", 3)); nodes.add(new Node("e", 4)); nodes.add(new Node("f", 13)); nodes.add(new Node("g"