C语言链表插入

来源:百度知道 编辑:UC知道 时间:2024/06/08 19:41:00
结点大小为4的链串,在其第m个字符后插入n个字符。(0<=n<=4)
结点: typedef struct node
{char date[4];
struct node *next;
}linklist;
linklist *s;
先输入字符建立链表S,以 \0 为结束标记。
然后插入n个字符。
求一个C语言程序。。。。。。。

char data[4]?
结点data是字符串?

抽时间帮你写了一个
有什么不合要求的地方你自己改改吧

#include <stdio.h>
#include <string.h>
#include <malloc.h>

typedef struct Lnode{
char *data;
struct Lnode *next;
}Lnode, *LinkList;

void CreateList(LinkList &L, char *buff)
{
int flag=0, j=0;
int len=strlen(buff);

L=(Lnode *)malloc(sizeof(Lnode));
L->next=NULL;
LinkList q=L;
for(int i=0;i<len;i+=4)
{
j=0;
LinkList p=(Lnode *)malloc(sizeof(Lnode));
q->next=p;
p->next=NULL;
p->data=(char *)malloc(sizeof(char)*5);
while(j<4)
{
p->data[j++]=buff[flag++];
}
p->data[4]='\0';
q=q->next;
}
}//初始化链表L

void TraverseList(LinkList L)
{
LinkList p;
p=L->next;
while(p)
{
printf("%s",p->data);
p=p->n