Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MorrisPrattSearch:public StringSearch
- {
- public:
- MorrisPrattSearch(string T,string W):StringSearch(T,W)
- {
- }
- void search()
- {
- int b, i, PI[W.size()+1],pp;
- PI[0] = b = -1;
- for(i = 1; i <= W.size(); i++)
- {
- while((b > -1) && (W[b] != W[i - 1]))
- b = PI[b];
- PI[i] = ++b;
- }
- pp = b = 0;
- for(i = 0; i < T.size(); i++)
- {
- while((b > -1) && (W[b] != T[i]))
- b = PI[b];
- if(++b == W.size())
- {
- while(pp < i - b + 1)
- {
- pp++;
- }
- cout <<"MORIS PRATT - Wzor wystepuje od miejsca "<<pp<<endl;
- pp++;
- b = PI[b];
- }
- }
- }
- const vector<int>&getoccurences()
- {
- return v;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement