1. 用java實現哈夫曼編碼
只要自己再加個類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;
}
}
2. 哈夫曼編碼與解碼 java
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; i<code.length; i++)
System.out.println(code[i]);
}
}
3. 哈夫曼編碼解碼器 java
建議: 用類似的方法,可以將某一學科的總分統計出來,並填入第48行相應的單元格中。
你好,由於內容比較多,先概述一下先。如圖所示,為我寫的一個壓縮軟體,原理是利用哈弗曼演算法實現的。我將資料整理好稍後就發到你郵箱,但在這里簡要說明一下代碼。
請看我的空間
http://hi..com/%D2%B6%BF%C6%C1%BC/blog
中的文章共5篇(太長了)
http://hi..com/%D2%B6%BF%C6%C1%BC/blog/item/93c35517bb528146f2de32fd.html
1.HuffmanTextEncoder類完成壓縮功能,可直接運行,壓縮測試用文本文件。
2.HuffmanTextDecoder類完成解壓縮功能,可直接運行,解壓縮壓縮後的文本文件。
3.BitReader,工具類,實現對BufferedInputStream的按位讀取。
4.BitWriter,工具類,實現按位寫入的功能。該類來自網路。
5.MinHeap<T>,模板工具類,實現了一個最小堆。生成Huffman樹時使用。
5. 哈夫曼樹編碼的應用(Java語言)
1)編寫函數實現選擇parent為0且權值最小的兩個根結點的演算法
2)編寫函數實現統計字元串中字元的種類以及各類字元的個數。
3)編寫函數構造赫夫曼樹。
4)編寫函數實現由赫夫曼樹求赫夫曼編碼表。
5)編寫函數實現將正文轉換為相應的編碼文件。
6)編寫函數實現將編碼文件進行解碼。
7)編寫主控函數,完成本實驗的功能。