MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / fillLPS

Function fillLPS

CPP/String/KMPalgo.cpp:4–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4void fillLPS(string s, int lps[])
5{
6 int n = s.length();
7 int len = 0;
8 int i = 1;
9 lps[0] = 0;
10 while (i < n)
11 {
12 if (s[i] == s[len])
13 {
14 len++;
15 lps[i] = len;
16 i++;
17 }
18 else
19 {
20 if (len == 0)
21 {
22 lps[i] = 0;
23 i++;
24 }
25 else
26 {
27 len = lps[len - 1];
28 }
29 }
30 }
31}
32
33void KMP(string txt, string pat)
34{

Callers 1

KMPFunction · 0.85

Calls 1

lengthMethod · 0.80

Tested by

no test coverage detected