main.cpp:4:17: error: string' has not been declared 4 | void KMPSearch(string pat, string txt) main.cpp:4:29: error: string' has not been declared 4 | void KMPSearch(string pat, string txt) main.cpp:31:25: error: 'string' has not been declared 31 | void computelPSArray(string pat, int M, int[] lps) Ananunun main.cpp:31:50: error: expected , or 31 | before lps' void computeLPSArray(string pat, int M, int[] lps)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
main.cpp:4:17: error: 'string' has not been declared
4 | void KMPSearch(string pat, string txt)
main.cpp:4:29: error: string' has not been declared
4 | void KMPSearch(string pat, string txt)
Aununun
main.cpp:31:25: error: string' has not been declared
31 |
void computelPSArray(string pat, int M, int[] lps)
main.cpp:31:50: error: expected
or .
before lps'
31 |
void computeLlPSArray(string pat, int M, int[] lps)
main.cpp:55:8: error: expected :' before 'static'
55 | public static void Main()
main.cpp:61:2: error: expected ;' after class definition
61 | }
|
main.cpp: In member function 'void GFG::KMPSearch(int, int)':
main.cpp:6:15: error: request for member Length' in 'pat', which is of non-class type 'int'
6 |
int M = pat.Length;
main.cpp:7:15: error: request for member Length' in txt’, which is of non-class type 'int'
int N = txt.Length;
main.cpp:8:6: warning: structured bindings only available with -std3c++17' or (-std=gnu++17'
8 |
int[] lps
new int[M];
Transcribed Image Text:main.cpp:4:17: error: 'string' has not been declared 4 | void KMPSearch(string pat, string txt) main.cpp:4:29: error: string' has not been declared 4 | void KMPSearch(string pat, string txt) Aununun main.cpp:31:25: error: string' has not been declared 31 | void computelPSArray(string pat, int M, int[] lps) main.cpp:31:50: error: expected or . before lps' 31 | void computeLlPSArray(string pat, int M, int[] lps) main.cpp:55:8: error: expected :' before 'static' 55 | public static void Main() main.cpp:61:2: error: expected ;' after class definition 61 | } | main.cpp: In member function 'void GFG::KMPSearch(int, int)': main.cpp:6:15: error: request for member Length' in 'pat', which is of non-class type 'int' 6 | int M = pat.Length; main.cpp:7:15: error: request for member Length' in txt’, which is of non-class type 'int' int N = txt.Length; main.cpp:8:6: warning: structured bindings only available with -std3c++17' or (-std=gnu++17' 8 | int[] lps new int[M];
main.cpp
1. class GFG {
void KMPSearch(string pat, string txt)
{
int M =
int N =
pat. Length;
txt.Length;
4
int[] lps
int j
6
new int[M];
0;
computeLlPSArray (pat, M, 1ps);
int i = 0;
while (i < N) {
if (pat[j]
j+t;
i++;
}
if (j == M) {
Console.Write("Found pattern
7
8
10
11
txt[i]) {
13
14
15
3%3D
16
+ "at index " + (i - j));
17
j = 1ps[j - 1];
}
else if (i < N && pat[j] != txt[i]) {
18
!!
19
20
21
22
if (j != 0)
j = 1ps[j
else
1];
23
24
i - i + 1;
25
}
}
26
27
28
void computelPSArray (string pat, int M, int[] lps)
{
29
30
int len = 0;
int i = 1;
1ps[0] = 0;
while (i < M) {
if (pat[i]
len++;
1ps[i]
i++;
}
else
31
%3D
32
33
34-
35
pat[len]) {
=3=
36
37
len;
=
38
39
40
{
if (len !- 0) {
len = 1ps[len
}
else
41
42
43
1];
%3D
44
45
{
1ps[i]
i++;
46
47
len;
%3D
48
49
50
}
51
52
public static void Main()
{
string txt = "ABABDABACDABABCABAB";
string pat
new GFG(). KMPSearch(pat, txt);
53
54
55
56
3 "АВАВСАВАВ"3;
57
58
59
}
60
111
Transcribed Image Text:main.cpp 1. class GFG { void KMPSearch(string pat, string txt) { int M = int N = pat. Length; txt.Length; 4 int[] lps int j 6 new int[M]; 0; computeLlPSArray (pat, M, 1ps); int i = 0; while (i < N) { if (pat[j] j+t; i++; } if (j == M) { Console.Write("Found pattern 7 8 10 11 txt[i]) { 13 14 15 3%3D 16 + "at index " + (i - j)); 17 j = 1ps[j - 1]; } else if (i < N && pat[j] != txt[i]) { 18 !! 19 20 21 22 if (j != 0) j = 1ps[j else 1]; 23 24 i - i + 1; 25 } } 26 27 28 void computelPSArray (string pat, int M, int[] lps) { 29 30 int len = 0; int i = 1; 1ps[0] = 0; while (i < M) { if (pat[i] len++; 1ps[i] i++; } else 31 %3D 32 33 34- 35 pat[len]) { =3= 36 37 len; = 38 39 40 { if (len !- 0) { len = 1ps[len } else 41 42 43 1]; %3D 44 45 { 1ps[i] i++; 46 47 len; %3D 48 49 50 } 51 52 public static void Main() { string txt = "ABABDABACDABABCABAB"; string pat new GFG(). KMPSearch(pat, txt); 53 54 55 56 3 "АВАВСАВАВ"3; 57 58 59 } 60 111
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY