資源簡介
lz算法實(shí)現(xiàn):輸入字符串,根據(jù)lz算法,輸出三元組。代碼可運(yùn)行,算法實(shí)現(xiàn)具體,c語言實(shí)現(xiàn)。
代碼片段和文件信息
#include
#include?“malloc.h“
#include?“string.h“
#define?NUM?30
?typedef?struct?triple
{
int?loc;
int?len;
char?nextch;
}TRIPLE;
typedef?struct?box
{
int?loc;
char?ch;
}?BOX;
typedef?struct?box1
{
int?loc;
int?len;
int?over;
}?BOX1;
enum?STAT_SELTCT
{
STAT_INIT
STAT_SELT
STAT_DONE
};
int?n=0;
int?number=0;
???//三元組的個(gè)數(shù)
?void??match(BOX?*pchar?*strBOX1?*plint?*tmpint?ilen)
{
int?num;
num=number-1;
int?location=0;;
int?loc;
int?len=0;
int?length=0;
????int?spos=0;
enum?STAT_SELTCT?stat;
int?over=0;
int?flag=0;?//第一次遇到匹配的地方
stat=STAT_INIT;
????while(num>=0)
{
switch(stat)
{
case??STAT_INIT:
if(p[num].ch==str[*tmp]?)
{
if?(flag?==?0)
{
spos?=?number?-?num;
flag?=?1;
}
????over=1;
???????stat=STAT_SELT;
}
???????? else
{
???????? num--;
}
break;
????case??STAT_SELT:
loc=number-num;
while(p[num].ch==str[*tmp]?&&?num {
?????????????len++;
?num++;
(*tmp)++;
}
評論
共有 條評論