From a29c9318199711ee52c41734cb6b9d2ecfb92e1a Mon Sep 17 00:00:00 2001 From: rajcode126 <93469376+rajcode126@users.noreply.github.com> Date: Mon, 31 Oct 2022 23:47:43 +0530 Subject: [PATCH] Delete KMPAlgorithm.cpp --- KMPAlgorithm.cpp | 74 ------------------------------------------------ 1 file changed, 74 deletions(-) delete mode 100644 KMPAlgorithm.cpp diff --git a/KMPAlgorithm.cpp b/KMPAlgorithm.cpp deleted file mode 100644 index 8e07b53c..00000000 --- a/KMPAlgorithm.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include - -void computeLPSArray(char* pat, int M, int* lps); -void KMPSearch(char* pat, char* txt) -{ - int M = strlen(pat); - int N = strlen(txt); - - int lps[M]; - computeLPSArray(pat, M, lps); - - int i = 0; - int j = 0; - while (i < N) { - if (pat[j] == txt[i]) { - j++; - i++; - } - - if (j == M) { - printf("Found pattern at index %d ", i - j); - j = lps[j - 1]; - } - - - else if (i < N && pat[j] != txt[i]) { - - if (j != 0) - j = lps[j - 1]; - else - i = i + 1; - } - } -} - - -void computeLPSArray(char* pat, int M, int* lps) -{ - - int len = 0; - - lps[0] = 0; // lps[0] is always 0 - - - int i = 1; - while (i < M) { - if (pat[i] == pat[len]) { - len++; - lps[i] = len; - i++; - } - else - { - - if (len != 0) { - len = lps[len - 1]; - - } - else - { - lps[i] = 0; - i++; - } - } - } -} - -int main() -{ - char txt[] = "ABABDABACDABABCABAB"; - char pat[] = "ABABCABAB"; - KMPSearch(pat, txt); - return 0; -}