📄 huffman.h
字号:
/////////////////////////////////////////////////////////////////////
// Huffman.h: interface for the Huffman class.
//
// PROGRAM BY : SINGLE LAO
// DATE : 2004. 5. 27
// VERSION : RELEASE
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_HUFFMAN_H__49D953E9_4F7C_49DB_8E66_F2D3B7D04E80__INCLUDED_)
#define AFX_HUFFMAN_H__49D953E9_4F7C_49DB_8E66_F2D3B7D04E80__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ExtBinTree.h"
#include <string>
#include <iostream>
#include <stack>
#include <fstream>
#include <math.h>
#include <cstdlib>
using namespace std;
class Code
{
friend class Huffman;
char data;
public:
Code(){};
Code(Code& item)
{
key = item.key;
data = item.data;
};
Code& operator + (Code& other)
{
Code result;
result.key = key + other.key;
result.data = 0;
return result;
}
long key;
};
struct CodePlan{
string code_plan;
char data;
CodePlan& operator = (CodePlan& item)
{
code_plan = item.code_plan;
data = item.data;
return *this;
};
};
class Huffman
{
private:
string format(char ch);
Code code[256],*Compress_Code;
MinHeap<ExtBinTree<Code> > *hp;
ExtBinTree<Code> tree;
CodePlan* code_plan;
string target;
long Code_plans,current_plan;
void make_code(Element<Code> *current,string str);
public:
void Demo();
void DecompressFile();
void Output_Codes();
void CompressFile();
void Decode();
void Make_Code();
void Creat_Huffman_Tree();
Huffman();
virtual ~Huffman();
void Add_Frequency(int n);
void Output_Code_Plan();
void Input_TargetString();
CodePlan& Find_Code_Plan(char ch);
};
#endif // !defined(AFX_HUFFMAN_H__49D953E9_4F7C_49DB_8E66_F2D3B7D04E80__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -