资源简介
lzw代码实现,使用了简单的字符"aabbbaabb",生成的编码为“20016463”
代码片段和文件信息
#include
#include
using namespace std;
//const char SigSource[] = “aabcabbbbd“;
typedef struct charIndex
{
string str;
int index;
}*CharIndex;
int main(int argc char* argv[])
{
int i j k;
int count = 0;
int charNum = 0;
int indexNum = 0;
string S1;
string S2;
string S12;
char binCode[20];
const string sigSource = “aabbbaabb“;
for (i = 0; i < sigSource.length(); i++)
{
for (j = 0; j < i; j++)
{
if (sigSource[j] == sigSource[i])
break;
}
if (j == i)
count++;
}
charNum = count;
CharIndex data = new charIndex[10];
count = 0;
for (i = 0; i < sigSource.length(); i++)
{
for (j = 0; j < i; j++)
{
if (sigSource[j] == sigSource[i])
break;
}
if (j == i)
{
data[count].str = sigSource.substr(i 1);
data[count].index = count;
count++;
}
}
indexNum = charNum;
data[indexNum].str = “LZW_CLEAR“;
data[indexNum].index = indexNum;
indexNum++;
data[indexNum].str = “LZW_EOI“;
data[indexNum].index = indexNum;
indexNum++;
for (i = 0; i < indexNum; i++)
{
cout << “data[“ << i << “]:“ << “ string is :“ << data[i].str
<< “ index is :“ << data[i].index << endl;
}
for (i = 0; i < indexNum; i++)
{
if (data[i].str == “LZW_CLEAR“)
{
binCode[0] = data[i].index + ‘0‘;
//S2.clear();
//S12.clear();
//S1.clear();
count = 1;
- 上一篇:c++连通区域标记 算法
- 下一篇:c++代码解析IP数据包
评论
共有 条评论