串的模式匹配(KMP算法)
2010-01-13 20:13
197 查看
KMP算法的核心在于,研究字串(模式串)存在的某种规律,总结出一种模式,使得主串指针不必回溯,而通过这种模式来移动字串指针或滑动字串,从而完成匹配。以下为:next[j]的代码
以下为测试代码:
using System; namespace Review { /// <summary> /// KMP算法next[j]算法 /// </summary> public class KMP { public static void GetNext(string t,int[] next) { int k=-1,j=0; next[0]=-1; while(j<t.Length-1) { if(k==-1||t[j]==t[k]) { j++; k++; next[j]=k; } else { k=next[k]; } } } } }
以下为测试代码:
using System; namespace Review { class Program { public static void Main(string[] args) { string str="abcabca"; int[] patten=new int[str.Length]; KMP.GetNext(str,patten); Console.ReadKey(); } } }
相关文章推荐
- 模式匹配KMP算法实现
- KMP算法 字符串模式匹配
- 模式匹配的KMP算法详解
- KMP算法 KMP模式匹配 一(串)
- 算法:模式匹配之KMP算法
- (11)串的模式匹配:朴素的模式匹配算法,KMP算法
- 串模式匹配之BF算法和KMP算法
- 【模式匹配】之 —— KMP算法详解及证明
- KMP算法--字符串模式匹配算法
- 字符串的模式匹配详解--BF算法与KMP算法
- 模式匹配kmp算法
- KMP算法 串的模式匹配算法优秀总结
- 改进的模式匹配算法——KMP算法
- 改进的模式匹配算法——KMP算法
- 改进的模式匹配算法——KMP算法
- 字符串模式匹配KMP算法
- 字符串模式匹配KMP算法
- 模式匹配-KMP算法
- 模式匹配之KMP算法的理解(二)
- 数据结构(11)--串的模式匹配算法之BF、KMP算法