Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. class MorrisPrattSearch:public StringSearch
  2. {
  3. public:
  4. MorrisPrattSearch(string T,string W):StringSearch(T,W)
  5. {
  6. }
  7. void search()
  8. {
  9. int b, i, PI[W.size()+1],pp;
  10.  
  11. PI[0] = b = -1;
  12.  
  13. for(i = 1; i <= W.size(); i++)
  14. {
  15. while((b > -1) && (W[b] != W[i - 1]))
  16. b = PI[b];
  17. PI[i] = ++b;
  18. }
  19.  
  20. pp = b = 0;
  21.  
  22. for(i = 0; i < T.size(); i++)
  23. {
  24. while((b > -1) && (W[b] != T[i]))
  25. b = PI[b];
  26. if(++b == W.size())
  27. {
  28. while(pp < i - b + 1)
  29. {
  30. pp++;
  31. }
  32. cout <<"MORIS PRATT - Wzor wystepuje od miejsca "<<pp<<endl;
  33. pp++;
  34. b = PI[b];
  35. }
  36. }
  37. }
  38.  
  39. const vector<int>&getoccurences()
  40. {
  41. return v;
  42. }
  43.  
  44. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement