#include<stdio.h>
#include<stdlib.h>
struct node
{
int num;
int L;
struct node *next;
};
typedef struct node LN;
LN *Creat(int n);
void print(LN *h);
void Revise(LN *p);
void main()
{
LN *h;
int a;
printf("Input the sum of the number:");
scanf("%d",&a);
h=Creat(a);
system("CLS");
Revise(h);
print(h);
}
LN *Creat(int n)
{
LN *head;
LN *p;
LN *b;
head=(LN *)malloc(sizeof(LN));
head->next=NULL;
b=head;
for(int i=1;i<=n;i++)
{
printf("Input the %d number:",i);
p=(LN *)malloc(sizeof(LN));
scanf("%d",&p->num);
b->next=p;
b=p;
p->L++;
}
system("CLS");
p->next=NULL;
return head;
}
void print(LN *h)
{
LN *p;
p=h->next;
while(p)
{
printf("%d\n",p->num);
p=p->next;
}
}
void Revise(LN *p)
{
LN *a;
LN *b;
int n;
int i=0;
int data;
printf("Input which node you want to insert:");
scanf("%d",&n);
printf("Please input the data:");
scanf("%d",&data);
while (i<n-1)
{
p=p->next;
i++;
}
a=(LN *)malloc(sizeof(LN));
b=(LN *)malloc(sizeof(LN));
p->num=data;
a=p->next;
p->next=b;
b->next=a;
}
其中在链表插入当中插入错误,插入节点是对的,但是数就是错的。