diff --git a/19.KMP.cpp b/19.KMP.cpp new file mode 100644 index 0000000..0181850 --- /dev/null +++ b/19.KMP.cpp @@ -0,0 +1,56 @@ +/* + * This program takes a text and a pattern and searches the pattern inside the text + * using Knuth- Morris- Pratt Algorithm + * + * Coded by: Abdurrezak Efe + * + * */ +#include + +using namespace std; + +int fail[10000]; //assuming pattern has a length less than or equal to 10000 + +void failure(string s) +{ + int i=1; + int j=0; + while(i0) + j = fail[j-1]; + else + fail[i] = 0, i++; + } +} + +int kmp(string text, string pattern) +{ + int i=0; + int j=0; + while(i0) + j = fail[j-1]; + else + i++; + } + return -1; + +} + +int main() +{ + string text, pattern; + cin >> text >> pattern; + + cout << kmp(text, pattern) << endl; +}