qq_34378013 于 2016.03.21 22:26 提问

``````#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 *p;
LN *b;
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;
}

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);
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;
}

``````

2个回答

caozhy      2016.03.21 22:36
``````
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);
scanf("%d",&data);
while (i<n)
{
p=p->next;
i++;
}
a=(LN *)malloc(sizeof(LN));
a->num=data;
a->next=p->next;
p->next=a;
}

``````
caozhy 回复qq_34378013: 问题解决请点下我回答右边的采纳，谢谢

qq_34378013 太感谢 知道错在哪儿了

caozhy      2016.03.21 22:40