System.out.println("please input the second letter!");
創新互聯公司專注為客戶提供全方位的互聯網綜合服務,包含不限于網站設計制作、網站設計、江城網絡推廣、小程序定制開發、江城網絡營銷、江城企業策劃、江城品牌公關、搜索引擎seo、人物專訪、企業宣傳片、企業代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創新互聯公司為所有大學生創業者提供江城建站搭建服務,24小時服務熱線:028-86922220,官方網址:vcdvsql.cn
char ch2 = tw.getChar();
if(ch2 == 'U') {System.out.println("Tuesday"); }
else if(ch2 == 'H') {System.out.println("Thursday"); }
class HaffmanNode //哈夫曼樹的結點類
{
int weight; //權值
int parent,left,right; //父母結點和左右孩子下標
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}; //指定權值集合
HaffmanTree htree = new HaffmanTree(weight);
System.out.println("哈夫曼樹的結點數組:\n"+htree.toString());
String[] code = htree.haffmanCode();
System.out.println("哈夫曼編碼:");
for (int i=0; icode.length; i++)
System.out.println(code[i]);
}
}
只要自己再加個類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;
}
}
1)編寫函數實現選擇parent為0且權值最小的兩個根結點的算法
2)編寫函數實現統計字符串中字符的種類以及各類字符的個數。
3)編寫函數構造赫夫曼樹。
4)編寫函數實現由赫夫曼樹求赫夫曼編碼表。
5)編寫函數實現將正文轉換為相應的編碼文件。
6)編寫函數實現將編碼文件進行譯碼。
7)編寫主控函數,完成本實驗的功能。
標題名稱:JAVA哈夫曼樹編碼代碼 java哈夫曼樹的編碼解碼
本文鏈接:http://vcdvsql.cn/article6/dopejog.html
成都網站建設公司_創新互聯,為您提供做網站、網站建設、定制開發、網站設計、網站改版、自適應網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯