```cpp
#include<iostream>
#include<stdio.h>
using namespace std;
typedef class bunch
{
public:
char a;
bunch *next;
}*LinkBunch,Link;
void creat_LinkBunch(LinkBunch &L,char t[]);
int StrLength(LinkBunch &L);
LinkBunch RepStr(LinkBunch &L1,int i,int j,LinkBunch &L2);//将L2插入到L1的i个位置开始连续j个字符构成的子串
void printlist(LinkBunch &L);
int main()
{
int i,j;
char a[30];
gets(a);
LinkBunch t1,t2;
creat_LinkBunch(t1,a);
printlist(t1);
gets(a);
creat_LinkBunch(t2,a);
printlist(t2);
cout<<"从第几个位置开始"<<endl;
cin>>i;
cout<<"连续几个位置"<<endl;
cin>>j;
LinkBunch t=RepStr(t1,i,j,t2);
printlist(t);
}
void creat_LinkBunch(LinkBunch &L,char t[])//ok
{
L=new Link;
L->next=NULL;
LinkBunch s,rear;
rear=L;
int i=0;
while(t[i]!='\0')
{
s=new Link;
s->a=t[i];
s->next=rear->next;
rear->next=s;
rear=s;
i++;
}
rear->next=NULL;
}
void printlist(LinkBunch &L)
{
LinkBunch p=L->next;
if(p==NULL)
{
return ;
}
else
{
while(p!=NULL)
{
cout<<p->a;
p=p->next;
}
}
cout<<endl;
}
int StrLength(LinkBunch &L)
{
LinkBunch p=L->next;
int i=0;
while(p!=NULL)
{
i++;
p=p->next;
}
return i;
}
LinkBunch RepStr(LinkBunch &L1,int i,int j,LinkBunch &L2)//将L2插入到L1的i个位置开始连续j个字符构成的子串
{
int k=1;
LinkBunch L=new Link;
L->next=NULL;
LinkBunch p=L1->next,q=L2->next;
LinkBunch rear=L;
LinkBunch s;
if(i>StrLength(L1)+1||i<1||i+j>StrLength(L1)||j<1)
{
return L;
}
while(k<i)
{
s=new Link;
s->a=p->a;
s->next=rear->next;
rear->next=s;
rear=s;
p=p->next;
k++;
}
k=1;
while(k<=j)
{
p=p->next;
k++;
}
while(q!=NULL)
{
s=new Link;
s->a=q->a;
s->next=rear->next;
rear->next=s;
rear=s;
q=q->next;
}
while(p!=NULL)
{
s=new Link;
s->a=p->a;
s->next=rear->next;
rear->next=s;
rear=s;
p=p->next;
}
return L;
}