
顺序查找&&字符串模式匹配
//链表节点
struct LNode{
char data;
struct LNode *next;
};
int match(struct LNode *A, struct LNode *B){
struct LNode *p=A->next;
int index=1;
while(p!=NULL){
struct LNode *m=p;
struct LNode *q=B->next; //每次匹配,q从头开始
while(m!=NULL&&q!=NULL){
if(m->data!=q->data)
break; //子串失败
m=m->next;
q=q->next;
}
if(q==NULL) //B完全匹配
return index;
p=p->next;
index++;
}
return -1;
}
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 AuraX
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果