资源简介
压缩文件有两个源码文件LZWCode.cpp和LZWDecode.cpp可以实现LZW的编码与解码,并有简要的使用说明文档。

代码片段和文件信息
#include
#include
#include
using namespace std;
class LZW{
public:
LZW();
void Code();
bool Find(string);
void Output(string);
void AddS(string);
void Print();
private:
int* code;//生成的字符串表中的编码
string* Str;//生成的字符串表中的字符
int* output;//原始字符串经压缩编码后生成的编码序列;
string K;//需要压缩的字符串
int N;//需要压缩的字符串的长度
int L;//当前字符串表中的记录数目
int L1;//当前压缩的编码长度
string s;
char c;
};
LZW::LZW ( )
{
ifstream fin;
fin.open (“code.txt“);
if(!fin)
cerr<<“文件打开失败!“< char temp;
fin.get(temp);
while(temp!=EOF)
{
K+=temp;
temp=EOF;
fin.get (temp);
}
fin.close ();
N=K.length ();
code=new int[N];
Str=new string[N];
output=new int[N];
L=0;
L1=0;
fin.clear ();
fin.open (“init.txt“);
if(!fin)
cerr<<“文件打开失败!“< fin.get (temp);
while(temp!=EOF)
{
Str[L]=temp;
fin>>code[L];
fin.get(temp);
if(temp!=EOF)
{
while(temp==‘ ‘&&!fin.eof ())
{
fin.get (temp);
}
if(temp!=EOF)
{
temp=EOF;
fin.get (temp);
}
}
L++;
}
fin.close ();
Code();
Print();
cout<<“被压缩的字符个数为“< cout<<“压缩比为“< }
void LZW::Code ( )
{
cout<<“正在进行压缩........“< cout<<“被压缩的字符串为“< cout< int m=0;
s=K[m];
while(m+1 {
m++;
c=K[m];
if(Find(s+c))
{
s=s+c;
}
else
{
Output(s);
AddS(s+c);
s=c;
}
}
Output(s);
}
bool LZW::Find(string t)
{
int i;
for(i=0;i {
if(t==Str[i])
break;
}
if(i==L)
return false;
else
return true;
}
void LZW::Output (string t)
{
int i;
for(i=0;i {
if(t==Str[i])
break;
}
output[L1]=code[i];
L1++;
}
void LZW::AddS (string t)
{
Str[L]=t;
code[L]=L+1;
L++;
}
void LZW::Print()
{
cout<<“压缩结果为“< ofstream fout;
fout.open(“yasuo.txt“);
for(int i=0;i {
cout< fout< }
cout< fout< cout<<“压缩结束!“< }
int main( )
{
LZW lzw;
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2251 2009-12-30 17:28 LZW的编码与解码\LZWCode.cpp
文件 1798 2009-12-30 17:35 LZW的编码与解码\LZWDecode.cpp
文件 520 2009-12-30 17:37 LZW的编码与解码\说明文档.txt
目录 0 2009-12-30 17:36 LZW的编码与解码
----------- --------- ---------- ----- ----
4569 4
- 上一篇:labview 用户登录程序
- 下一篇:IIC Linux 应用层的两种操作方式
相关资源
- 瑞利信道的仿真,包括信号的调制,
- 八三编码器设计 VHDL代码 简单,包附
- 在高斯白噪声信道下的QPSK编码误码率
- 信息论与编码(仇佩亮编著 高等教育
- UNICODE GBK双向码表二进制文件
- LPC线性预测分析及编码
- 常用编码(UnicodeUTF-8GBK)转换工具
- L-Z编码L-Z解码
- 1553曼彻斯特编码程序
- 全自动多功能编码转换工具(URLASCI
- H.264编码器流程图
- lzw压缩,解压缩算法
- 建立文件数据索引的c 代码
- 易语言QQTEA算法源码
- XSS Encode
- 基于三菱PLC-松下A6伺服485通讯-读编码
- LabVIEW 数据采集 模拟量+编码器(Daq
- UTF8编码表汉字对照
- H.264视频编码基本知识
- 6通道增量式编码器在智控型纺织机的
- 矿井巷道时频编码协作MC-CDMA信道估计
- 易语言查询话费欠费信息源码
- 易语言图像编码、解码器源码易语言
- 哈夫曼树编码和译码实验报告+运行视
- Huffman Compress 霍夫曼编码 压缩 解压缩
- 编码 隐匿在计算机软硬件背后的语言
- X264实时编码,FFmpeg实时解码
- 使用FFmpeg采集摄像头图像和麦克风音
- Big5编码台湾繁体字体和GBK编码简体字
- Eclipse专业配色方案 - 让编码更舒适高
评论
共有 条评论