块链串的插入与删除操作【C语言】
__S是用结点大小为4的单链表存储的链串,试实现:
(1)在第k个字符后插入串T
(2)从第k个字符删除len个字符
__
#include <stdio.h>
#include <stdlib.h>
#define size 4
#define Seqsize 100
int num=0;
typedef struct
{
char ch[Seqsize];
int len;
}Seqstring;
typedef struct Node
{
char ch[size];
struct Node *next;
}Node;
typedef struct
{
Node *head;
Node *tail;
int len;
}Linkstring;
void Initstring(Linkstring *S)
{
S->len=0;
S->head=S->tail=NULL;
}
void Create(Linkstring *S)
{
if(S->len==0)
{
return;
}
int j=1;
if(S->len>=size)
{
j=(S->len)/size;
if((S->len)%size!=0)
{
j++;
}
}
Node *p,*q=NULL;
int i;
for(i=0;i<j;i++)
{
p=(Node*)malloc(sizeof(Node));
if(p==NULL)
{
return;
};
int k;
if(i!=j-1)
{
for(k=0;k<size;k++)
{
scanf(" %c",&p->ch[k]);
}
}
else
{
int NUM=S->len-((i)*size);
for(k=0;k<NUM;k++)
{
scanf(" %c",&p->ch[k]);
}
p->ch[k+1]='\n';
};
if(i==0)
{
S->head=p;
q=S->head;
if(j=