一、基本思想
用指向早期曾经出现过的字符串的指针来表示当前被编码的字符串,如:
二、LZ77算法
- 算法伪码:
- 示意图:
- 举例:
三、C/C++实现
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct code {
int off;
int len;
char nextChar;
};
#define maxWindow 10
vector<code> vt;
int main(int argc, char* argv[]) {
//string str = "abacdbacc";
string str = "abcdbbccaaabaeaaabaee";
cout << str << endl;
int window1, window2;
//编码
for(int i