Today, I finally understand the KMP in the string of the character string, I will write down, it is convenient to check it later.
Failure function: set mode P = P
0P
1 .... p
M-2P
M-1, then its fail function is defined as follows:
f (j) = k | When 0 <= k J-KP J-K 1 ... P maximum number of J f (j) = -1 | Other situations. J01234567Pabaabcacf (j) -1-1001-10-1 is detailed, remember the algorithm. Void String :: fail {INT lengthp = curlen; f [= 1; j Here is a normal matching algorithm: int String :: Find (String & PAT) Const {Char * p = pat.ch; * s = ch; int i = 0; if (* p && * s) while (i <= curlen-pat.curlen) if (* p == * s ) {// C classics if (! * P) return i;} else {i ; s = CH i; p = pat.ch;} return -1;} Here is the KMP algorithm: int String :: fastfind (String) & PAT) Const {INT POSP = 0, PAST = 0; intlengthp = pat.curlen, lengtht = curlen; while (POSP