主题:串的基本操作
为什么没结果啊
#include<iostream.h>
#define maxlen 100
typedef struct
{
char ch[maxlen];
int len;
}seqstring;
int strinsert(seqstring *s,int pos,seqstring *t) //串的插入
{
int i;
if(pos<0||pos>s->len+1)
return 0;
if(s->len+t->len<maxlen)
{
for(i=s->len+t->len+1;i>t->len+pos;i--)
s->ch[i]=s->ch[i-t->len-1];
for(i=0;i<=t->len;i++)
s->ch[i+pos]=t->ch[i];
s->len=s->len+t->len+1;
}
else
{
if(pos+t->len<=maxlen)
{
for(i=maxlen-1;i>t->len+pos;i--)
s->ch[i]=s->ch[i-t->len-1];
for(i=0;i<t->len;i++)
s->ch[i+pos]=t->ch[i];
s->len=maxlen-1;
}
else
{
for(i=0;i<maxlen-pos;i++)
s->ch[i+pos]=t->ch[i];
s->len=maxlen-1;
}
}
return 1;
}
int strdelete(seqstring *s,int pos,int len) //串的删除
{
int i;
if(pos<0||pos>(s->len-len))
return 0;
for(i=pos+len;i<=s->len;i++)
s->ch[i-len]=s->ch[i];
s->len=s->len-len;
return 1;
}
void main()
{
seqstring x={"I am a student"};
seqstring y={"me too"};
strinsert(&x,14,&y);
for(int i=0;i<x.len;i--)
{
cout<<x.ch[i];
}
}
#include<iostream.h>
#define maxlen 100
typedef struct
{
char ch[maxlen];
int len;
}seqstring;
int strinsert(seqstring *s,int pos,seqstring *t) //串的插入
{
int i;
if(pos<0||pos>s->len+1)
return 0;
if(s->len+t->len<maxlen)
{
for(i=s->len+t->len+1;i>t->len+pos;i--)
s->ch[i]=s->ch[i-t->len-1];
for(i=0;i<=t->len;i++)
s->ch[i+pos]=t->ch[i];
s->len=s->len+t->len+1;
}
else
{
if(pos+t->len<=maxlen)
{
for(i=maxlen-1;i>t->len+pos;i--)
s->ch[i]=s->ch[i-t->len-1];
for(i=0;i<t->len;i++)
s->ch[i+pos]=t->ch[i];
s->len=maxlen-1;
}
else
{
for(i=0;i<maxlen-pos;i++)
s->ch[i+pos]=t->ch[i];
s->len=maxlen-1;
}
}
return 1;
}
int strdelete(seqstring *s,int pos,int len) //串的删除
{
int i;
if(pos<0||pos>(s->len-len))
return 0;
for(i=pos+len;i<=s->len;i++)
s->ch[i-len]=s->ch[i];
s->len=s->len-len;
return 1;
}
void main()
{
seqstring x={"I am a student"};
seqstring y={"me too"};
strinsert(&x,14,&y);
for(int i=0;i<x.len;i--)
{
cout<<x.ch[i];
}
}