KMP算法
来源:互联网 发布:python 每秒执行一次 编辑:程序博客网 时间:2024/05/01 03:29
今天把放了一年多都没有看过的模式匹配算法又拿出来复习了一下,顺便在这里留点记号。
void get_next(char * str, int len, int nextVal[])
...{
int i = 0;
int j = -1;
nextVal[0] = -1;
while( i < len )
...{
if( j == -1 || str[i] == str[j] )
...{
i++;
j++;
nextVal[i] = j;
}
else
...{
j = nextVal[j];
}
}
}
...{
int i = 0;
int j = -1;
nextVal[0] = -1;
while( i < len )
...{
if( j == -1 || str[i] == str[j] )
...{
i++;
j++;
nextVal[i] = j;
}
else
...{
j = nextVal[j];
}
}
}
下面是记过修正后的算法:
void get_nextEx(char * str, int len, int nextVal[])
...{
int i = 0;
int j = -1;
nextVal[0] = -1;
while( i < len )
...{
if( j == -1 || str[i] == str[j] )
...{
i++;
j++;
if( str[i] != str[j] )
...{
nextVal[i] = j;
}
else
...{
nextVal[i] = nextVal[j];
}
}
else
...{
j = nextVal[j];
}
}
}
...{
int i = 0;
int j = -1;
nextVal[0] = -1;
while( i < len )
...{
if( j == -1 || str[i] == str[j] )
...{
i++;
j++;
if( str[i] != str[j] )
...{
nextVal[i] = j;
}
else
...{
nextVal[i] = nextVal[j];
}
}
else
...{
j = nextVal[j];
}
}
}
- KMP算法详解 【KMP】
- 【KMP】KMP算法模板
- KMP hihoCoder1015 KMP算法
- kmp算法
- KMP算法
- KMP算法
- KMP算法
- KMP算法
- KMP 算法
- kmp算法
- KMP算法
- kmp算法
- KMP算法
- KMP算法
- kmp算法
- kmp算法
- KMP算法
- KMP算法
- 关于开放CWSS群组通知
- 矩阵的乘法问题
- ubuntu初体验
- 翻译(一)SharePoint 2007管理入门:Windows SharePoint Service 3.0 and Microsoft Office SharePoint Server 2007
- 矩阵乘法
- KMP算法
- webBrowser控制新窗口
- Linux那些事儿之我是UHCI(29)FSBR
- Linux那些事儿之我是UHCI(大结局)"脱"就一个字
- Proxool Provider unable to load JAXP configurator file: proxool.xml
- ACE研读笔记之五-循环式日志服务器
- 配置连接池
- php编程常见问题
- log4j 配置