int BoyerMooreSearch char text char pat int table 256 int len strlen p

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int BoyerMooreSearch(char* text, char* pat)
{
int i, table[256];
int len=strlen(pat);
int no=0;
//int *pos=0;
int compcount=0;
for (i=0; i<256; i++) table[i]=len;
for (i=0; i<len; i++) table[pat[i]]=len-(i+1);
int ptct=len-1;
while (ptct<strlen(text))
{
int count=0;
while (count<len)
{
if (text[ptct-count]!=pat[len-1-count])
{
compcount++;
break;
}
else count++;
}
if (count==len)
{
no++;
//*(pos+(*no)-1)=(ptct-count+1);
ptct+=len;
}
else ptct+=(table[text[ptct-count]]-count);
}
return no;
}