修改main()为插入删除
#include<stdlib.h>#include<stdio.h>
typedef struct Node
{
int data;
struct Node *next;
}LNode,*LinkedList;
VisitLinkedList(LinkedList L)
{
LNode *p;
p=(LNode*)malloc(sizeof(LNode));
p=L->next;
while(p!=NULL)
{
printf("%d\n",p->data);
p=p->next;
}
}
main()
{
int X,q,i=1;
LinkedList L;
LNode *p,*r,*s,*pre,*m,*n;
L=(LNode*)malloc(sizeof(LNode));
L->next=NULL;
r=L;
scanf("%d",&X);
while(X!=0)
{
p=(LNode*)malloc(sizeof(LNode));
p->data=X;
p->next=r->next;
r->next=p;
r=p;
scanf("%d",&X);
}
VisitLinkedList(L);
printf("请输入要插入的数和位置");
scanf("%d %d",&X,&q);
s=(LNode*)malloc(sizeof(LNode));
s->data=X;
pre=L;
while(i!=q)
{
pre=pre->next;
i++;
}
s->next=pre->next;
pre->next=s;
VisitLinkedList(L);
}