Brutr-Force算法:当比较字串失败后,返回到初始比较的下一字节
int strstr1(const char *str, const char *substr)
{
assert(NULL != str || NULL != substr);
int index = 0;
int temp =0;
int subIndex = 0;
while(*str)
{
if(*str == *substr)
{
temp = index;
subIndex = 0;
while((*substr != NULL) && (*str != NULL) && (*str == *substr))
{
index++;
subIndex++;
substr++;
str++;
}
if(*str - *substr == 0)
{
break;
}
substr -= subIndex;
str -= index-temp;
index = temp;
temp = -1;
}
index++;
str++;
}
return temp;
}