哈夫曼樹(三)之 Java詳解
阿新 • • 發佈:2018-12-30
public class HuffmanNode implements Comparable, Cloneable { protected int key; // 權值 protected HuffmanNode left; // 左孩子 protected HuffmanNode right; // 右孩子 protected HuffmanNode parent; // 父結點 protected HuffmanNode(int key, HuffmanNode left, HuffmanNode right, HuffmanNode parent) { this.key = key; this.left = left; this.right = right; this.parent = parent; } @Override public Object clone() { Object obj=null; try { obj = (HuffmanNode)super.clone();//Object 中的clone()識別出你要複製的是哪一個物件。 } catch(CloneNotSupportedException e) { System.out.println(e.toString()); } return obj; } @Override public int compareTo(Object obj) { return this.key - ((HuffmanNode)obj).key; } }