直接上代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace dotnetKMP
{
class Program
{
public static int[] strNext;//失效函数值
static void Main(string[] args)
{
const string strForTest = "abaabcac";
const string strForAim = "abaabcac";
SetNext(strForTest);
int i = KMP(strForAim, strForTest);
Console.Read();
}
/// <summary>
/// 对输入串进行失效匹配初始化
/// </summary>
public static void SetNext( string inputStr)
{
int strLen = inputStr.Length;
strNext = new int[strLen];
int i = 0, j =