完成链串结构下的模式匹配(子串定位)应用。
输入一段字符串:They are student
它的子串:are
主串通过链表的形式存储,然后运用串模式匹配算法定位子串
#include#include using namespace std; typedef struct Link { char data; struct Link * next; }link,*Plink; Plink initLink(Plink head, char * str); void TraverseLink(Plink head); void Match(Plink head,char *a,int &n); int main() { Plink head = NULL; int n; char s[]="They are students"; char a[]="are"; head = initLink(head,s); TraverseLink(head); Match(head,a,n); cout< next = NULL; Plink temp = head;//头指针指向头结点 //初始化链表 for (i = 0; i data=str[i]; newlink->next = NULL; temp->next = newlink;//尾插法 temp = newlink; } return head; } //输出链表 void TraverseLink(Plink head) { Plink temp = head->next; while (temp) { cout< data; temp = temp->next; } } //模式匹配 void Match(Plink head,char *a,int &n){ int length=0; char b[30]; Plink p=head->next; int i=0,j=0; while(p){ b[length++]=p->data; p=p->next; } while(i



