你這是屬于畢設(shè)?還是課程設(shè)計(jì)?自己好好學(xué)習(xí)看看吧,別什么都問,如果在做到過程中遇到問題,大家都會(huì)很樂意回答的
創(chuàng)新互聯(lián)自2013年起,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站設(shè)計(jì)制作、網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元青山做網(wǎng)站,已為上家服務(wù),為青山各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220
class HaffmanNode //哈夫曼樹的結(jié)點(diǎn)類
{
int weight; //權(quán)值
int parent,left,right; //父母結(jié)點(diǎn)和左右孩子下標(biāo)
public HaffmanNode(int weight)
{
this.weight = weight;
this.parent=-1;
this.left=-1;
this.right=-1;
}
public HaffmanNode()
{
this(0);
}
public String toString()
{
return this.weight+", "+this.parent+", "+this.left+", "+this.right;
}
return code;
}
public static void main(String[] args)
{
int[] weight={5,29,7,8,14,23,3,11}; //指定權(quán)值集合
HaffmanTree htree = new HaffmanTree(weight);
System.out.println("哈夫曼樹的結(jié)點(diǎn)數(shù)組:\n"+htree.toString());
String[] code = htree.haffmanCode();
System.out.println("哈夫曼編碼:");
for (int i=0; icode.length; i++)
System.out.println(code[i]);
}
}
只要自己再加個(gè)類Tree就可以了。
代碼如下:
public class Tree {
double lChild, rChild, parent;
public Tree (double lChild, double rChild, double parent) {
this.lChild = lChild;
this.rChild = rChild;
this.parent = parent;
}
public double getLchild() {
return lChild;
}
public void setLchild(double lChild) {
this.lChild = lChild;
}
public double getRchild() {
return rChild;
}
public void setRchild(double rChild) {
this.rChild = rChild;
}
public double getParents() {
return parent;
}
public void setParents(double root) {
this.parent = root;
}
}
可以在Dog與Cat類中重寫Animal中的animalDo方法,通過調(diào)用animalDo方法,
然后會(huì)自動(dòng)根據(jù)不同的實(shí)例調(diào)用不同類中的方法(多態(tài)知識(shí))。