资源简介
自适应霍夫曼编码的C++版本简单实现
class AdaptiveTree {
public:
AdaptiveTree(int rootNum);
AdaptiveTree(int rootNum, string str);
void swap(int first, int second); // swap two nodes of the tree
void initalCode(); // initializing the data
string char2code(unsigned char letter); // locate the character in the tree with its corresponding binary string and return the string
string char2binary(unsigned char letter); // translating the character to the 8-bit binary string
unsigned char binary2char(string bin); // translating the binary string: bin to the corresponding character
int spawn(unsigned char letter); // add a new character to the original tree
void updateTree(unsigned char newchar); // update the tree
int highestInBlock(int count); // return the highest node to be exchanged
void setString(string str); //
string decodingStr() const;
void encoding();
string decoding();
unsigned char code2char(string bincode);
static int size();
string binStr() const; // return the binary string of string: tempString
private:
void run();
int findchar(unsigned char letter ); // locate the letter in the tree
string tempString; //temp string to be encoded needed to be stored here
string deStr;// used for storing the decoding string
string bin; // used for storing the result of encoding process
/* Adaptive Tree data members */
HuffmanTree *tree;
int root;
/* Adaptive Tree constants */
static int ALPH_SIZE; // size of the alphabet
static unsigned char none; // not a unsigned character
static unsigned char NYT; // Not Yet transmitted code
};

代码片段和文件信息
#include
#include
#include
#include
#define PSEUDO_EOF 3
using namespace std;
struct HuffmanTree{
unsigned char letter; // the unsigned character of each code
int count; // frequency of each unsigned character
int left; // the left child of each node
int right; // the right child of each node
int parent; // the parent of each node
public:
bool operator==(const HuffmanTree& node) const;
bool operator!=(const HuffmanTree& node) const;
};
bool HuffmanTree::operator==(const HuffmanTree& node) const
{
return node.count == count && node.letter == letter && node.left == left && node.right == right && node.parent == parent;
}
bool HuffmanTree::operator!=(const HuffmanTree& node) const
{
return node.count != count || node.letter != letter || node.left != left || node.right != right || node.parent != parent;
}
class AdaptiveTree {
public:
AdaptiveTree(int rootNum);
AdaptiveTree(int rootNum string str);
void swap(int first int second); // swap two nodes of the tree
void initalCode(); // initializing the data
string char2code(unsigned char letter); // locate the character in the tree with its corresponding binary string and return the string
string char2binary(unsigned char letter); // translating the character to the 8-bit binary string
unsigned char binary2char(string bin); // translating the binary string: bin to the corresponding character
int spawn(unsigned char letter); // add a new character to the original tree
void updateTree(unsigned char newchar); // update the tree
int highestInBlock(int count); // return the highest node to be exchanged
void setString(string str); //
string decodingStr() const;
void encoding();
string decoding();
unsigned char code2char(string bincode);
static int size();
string binStr() const; // return the binary string of string: tempString
private:
void run();
int findchar(unsigned char letter ); // locate the letter in the tree
string tempString; //temp string to be encoded needed to be stored here
string deStr;// used for storing the decoding string
string bin; // used for storing the result of encoding process
/* Adaptive Tree data members */
HuffmanTree *tree;
int root;
/* Adaptive Tree constants */
static int ALPH_SIZE; // size of the alphabet
static unsigned char none; // not a unsigned character
static unsigned char NYT; // Not Yet transmitted code
};
int AdaptiveTree::ALPH_SIZE = 1024;
unsigned char AdaptiveTree::NYT = 255;
unsigned char AdaptiveTree::none = 254;
string AdaptiveTree::decodingStr() const
{
return deStr;
}
unsigned char AdaptiveTree::binary2char(string bin)
{
int n = bin.length();
int tempchar=0i;
for (i=0; i {
tempchar += (bin[i] - ‘0‘) * (int)pow(2i);
}
return (unsigned char)(tempchar);
}
int Adaptive
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 11778 2009-05-22 17:11 adaptiveHuffmanCoding.cpp
----------- --------- ---------- ----- ----
11778 1
- 上一篇:TstCon.exe
- 下一篇:hello world ,stm32串口打印程序
相关资源
- c++ 数据结构 哈夫曼压缩&解压软件 控
- C++文本文件无失真压缩 Huffman
- Huffman和算术编码的C++实现
- Huffman编码MFC版本
- 用哈夫曼编码压缩文件
- 数据结构实习 软件压缩/解压缩软件
- c++自适应哈夫曼编码
- Expert C++: Become a proficient programmer by
- Huffman编码(c++版本)_数据结构与算法
- c语言哈夫曼编码编码+译码,有注释
- 基于c语言的huffman图像编解码
- 基于huffman编码的文件解压缩程序(
- 基于Huffman树的文件压缩C语言源码数据
- Huffman编码(二叉树应用)
- Huffman编码以及其编码效率的计算
- 基于哈夫曼编码的文件压缩解压程序
- C语言 Huffman编码
- Huffman 编码器与解码器-----数据结构课
- 赫夫曼树的构建及赫夫曼编码C语言源
- 哈夫曼树的建立(Huffman Tree C语言实现
- 实现对任意格式文件压缩 C++
- Huffman 编码
- Huffman编/译码器C语言代码
- 霍夫曼编码C++实现
- 哈夫曼压缩解压算法-C语言
- 各种压缩算法C++实现
- 26个大写字符和空格的Huffman编码
- huffmantree对英文短文编码,译码
- huffman算法源码
- Huffman课程设计
评论
共有 条评论