关于kmp的简单解说

来源:互联网 发布:手机qq皮肤制作软件 编辑:程序博客网 时间:2024/05/29 04:49

在网上发现一篇关于kmp的nice解说,所以就把他的思路分享给大家 下面是原作者的博客 点击打开链接。


再分享下我的关于求next[]部分匹配值的我自己的代码

#include<iostream>#include<string.h>using namespace std;void sort(  char a[],int next[]){int x = 0;for (int i = 1; i < strlen(a); i++){while (x > 0 && a[i] != a[x]){x = next[x - 1];}if (a[i] == a[x]){x++;}next[i] = x;}}void main(){      char a[] = "abcdabd";intnext[20] = { 0 };sort(a, next);for (int i = 0; i < strlen(a);i++){cout << next[i] << " ";}system("pause");}

0 0
原创粉丝点击