Posts

Showing posts with the label pattern matching

KMP pattern matching

/*** Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char txt[]) that prints all occurrences of pat[] in txt[]. You may assume that n > m. Examples: 1) Input:   txt[] =  "THIS IS A TEST TEXT"   pat[] = "TEST" Output:    Pattern found at index 10 2) Input:   txt[] =  "AABAACAADAABAAABAA"   pat[] = "AABA" Output:    Pattern found at index 0    Pattern found at index 9    Pattern found at index 13 ***/ #include <iostream> #include <vector> #include <string> using namespace std; class KMPmatching { public :        KMPmatching( string , string );        vector < int > matching();        ~ KMPmatching(); private :        string str;        ...