Saturday, 7 September 2013

BRUTE FORCE, Is the following algorithm implemented correctly? C++

BRUTE FORCE, Is the following algorithm implemented correctly? C++

I am trying to take a string P and match it to string T (original string).
This is what I have for now, I am not sure if it is correct:
int bruteForce(string T,string P) {
int n,m;
for (int i=0;i<= n-m;i++) {
int j = 0;
while (j < m && T[i+j] == P[j]) {
if(j == m) {
return i;
}
return 0;
}
}
}

No comments:

Post a Comment