Question: Where in the c# code can i enter the information to print to console? Console.WriteLine(Pattern found at:{0}, i); Console.WriteLine(pattern) public void preKMP() { int m
Where in the c# code can i enter the information to print to console?
Console.WriteLine("Pattern found at:{0}", i);
Console.WriteLine(pattern)
public void preKMP() { int m = pattern.Length; int k; f[0] = -1; for (int i = 1; i < m; i++) { k = f[i - 1]; while (k >= 0) { if (pattern[k] == pattern[i - 1]) break; else k = f[k]; } f[i] = k + 1; } }
public int Search() // s is string sequence, pattern is what is inputted from user {
//kmp algorithm is executed here
int m = pattern.Length; int n = s.Length; int[] f = new int[m];
preKMP(); int i = 0; int k = 0;
while (i < n) { if (k == -1) { ++i; k = 0; } else if (s[i] == pattern[k]) { i++; k++; if (k == m) return 1;
} else k = f[k];
} return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
