自己写的字符串搜索算法,求复杂度
以下为代码:
#include "stdio.h"
#include "windows.h"
#include "winbase.h"
//函数功能:查找send在fir中出现的位置
int FindString(char *fir,char *send)
{
int i=0;
int j=0;
int size= strlen(fir);
int start = 0;
int ii = strlen(send);
char *a = fir;
char *b = send;
//清空内存
char *p = malloc(sizeof(char)*ii);
ZeroMemory(p,strlen(send));
for(i=0;i<size;i++)
{
if(a==b)
{
j++;
if(j==ii)
{
return i-ii;
}
p=1;
start++;
}
else
{
j=0;
p=0;
start=0;
}
}
for (i=0;i<ii;i++)
{
if(0==p)
return 0;
}
free(p);
return 1;
}
int main(void)
{
int i= FindString("http://bbs.fishc.com/forum.php?mod=post&action=newthread&fid=79&referer=http%3A//bbs.fishc.com/forum-79-1.html","fishc");;
printf("%d",i);
return 0;
}
页:
[1]