//分配 复制 相等 求长 合并 子串 串插串 删除 替代 打印
#include
using namespace std;
typedef struct SNode{
char data;
struct SNode *next;
}LinkString;
LinkString *Assign(char t[]){
LinkString *r,*p,*s=new LinkString;
s->next=NULL;
r=s;
for (int i=0;t[i]!='\0';i++){
LinkString *p=new LinkString;
p->data=t[i];
p->next=NULL;
r->next=p;
r=p;
}
return s;
}
void Copy(LinkString *&s,LinkString *t){
LinkString *p=t->next,*q,*r;
s->next=NULL;
r=s;
while(p){
LinkString *q=new LinkString;
q->data=p->data;
q->next=NULL;
r->next=q;
r=q;
p=p->next;
}
}
int Equal(LinkString *s,LinkString *t){
LinkString *p=s->next,*q=t->next;
while (p&&q&&p->data==q->data){
p=p->next;
q=q->next;
}
if (p==NULL&&q==NULL) return 1;
else return 0;
}
int Length(LinkString *s){
int i=0;
LinkString *p=s->next;
while(p){
p=p->next;
i++;
}
return i;
}
LinkString *Concat(LinkString *s,LinkString *t){
LinkString *str=new LinkString,*p=s->next,*q,*r;
str->next=NULL;
r=str;
while(p){//复制s
LinkString *q=new LinkString;
q->data=p->data;
q->next=NULL;
r->next=q;
r=q;
p=p->next;
}
p=t->next;
while(p){//复制t
LinkString *q=new LinkString;
q->data=p->data;
q->next=NULL;
r->next=q;
r=q;
p=p->next;
}
return str;
}
LinkString *Sub(LinkString *s,int i,int j){//对s取i-j的子串
LinkString *str=new LinkString,*p=s->next,*q,*r;
str->next=NULL;
r=str;
if (i<=0 || i>Length(s) || j<0 || i+j-1>Length(s)) return str;
for (int k=0;knext;
for (int k=1;k<=j;k++){
LinkString *q=new LinkString;
q->data=p->data;
q->next=NULL;
r->next=q;
r=q;
p=p->next;
}
return str;
}
LinkString *Ins(LinkString *s,LinkString *t,int i){
LinkString *str=new LinkString,*p=s->next,*p1=t->next,*q,*r;
str->next=NULL;
r=str;
if (i<=0 || i>Length(s)+1) return str;
for(int k=1;kdata=p->data;
q->next=NULL;
r->next=q;
r=q;
p=p->next;
}
while(p1){ //将t的所有结点复制到str
LinkString *q=new LinkString;
q->data=p1->data;
q->next=NULL;
r->next=q;
r=q;
p1=p1->next;
}
while(p){ //将*p及其后的结点复制到str
LinkString *q=new LinkString;
q->data=p->data;
q->next=NULL;
r->next=q;
r=q;
p=p->next;
}
return str;
}
LinkString *Delete(LinkString *s,int i,int j){
LinkString *str=new LinkString,*p=s->next,*q,*r;
str->next=NULL;
r=str;
if (i<=0 || i>Length(s) || j<0 || i+j-1>Length(s)) return str;
for (int k=0;kdata=p->data;
q->next=NULL;
r->next=q;
r=q;
p=p->next;
}
for (int k=0;knext;
while(p){ //将*p及其后的结点复制到str
LinkString *q=new LinkString;
q->data=p->data;
q->next=NULL;
r->next=q;
r=q;
p=p->next;
}
return str;
}
LinkString *Represent(LinkString *s,LinkString *t,int i,int j){
LinkString *str=new LinkString,*p=s->next,*p1=t->next,*q,*r;
str->next=NULL;
r=str;
if (i<=0 || i>Length(s) || j<0 || i+j-1>Length(s)) return str;
for (int k=0;kdata=p->data;
q->next=NULL;
r->next=q;
r=q;
p=p->next;
}
for (int k=0;knext;
while(p1){ //将t的所有结点复制到str
LinkString *q=new LinkString;
q->data=p1->data;
q->next=NULL;
r->next=q;
r=q;
p1=p1->next;
}
while(p){ //将*p及其后的结点复制到str
LinkString *q=new LinkString;
q->data=p->data;
q->next=NULL;
r->next=q;
r=q;
p=p->next;
}
return str;
}
void Disp(LinkString *s){
LinkString *p=s->next;
while (p){
cout<data<<" ";
p=p->next;
}
cout<<"\n";
}
int main(){
char n1[]={'z','s','h','z','s'};
char n2[]={'f','n','z','m'};
LinkString *s=Assign(n1);
LinkString *t=Assign(n2);
Disp(s);
Copy(s,t);
Disp(s);
cout<