C 一个链表插入的问题!

来源:百度知道 编辑:UC知道 时间:2024/06/10 18:46:03
#include<stdio.h>
#include<stdlib.h>
struct student
{
int num;
float add;
struct student *next;
};
int n;

struct student *fun1()
{
struct student *p1,*p2,*head;
n=0;

p1=(struct student *)malloc(sizeof(struct student));

scanf("%d,%f",&p1->num,&p1->add);
head=NULL;

while(p1->num!=0)
{
n+=1;
if(n==1)
head=p1;

else
p2->next=p1;

p2=p1;

p1=(struct student *)malloc(sizeof(struct student));
scanf("%d,%f",&p1->num,&p1->add);

}
p2->next=NULL;
return (head);
}

void fun2(struct student *head)
{
struct student *p;
p=head;
while(p!=NULL)
{
printf("%d %f\n",p->num,p->add);
p=p->next;

#include<stdio.h>
#include<stdlib.h>
struct student
{
int num;
float add;
struct student *next;
};
int n;

struct student *fun1()
{
struct student *p1,*p2,*head;
n=0;

p1=(struct student *)malloc(sizeof(struct student));

scanf("%d,%f",&p1->num,&p1->add);
head=NULL;

while(p1->num!=0)
{
n+=1;
if(n==1)
head=p1;

else
p2->next=p1;

p2=p1;

p1=(struct student *)malloc(sizeof(struct student));
scanf("%d,%f",&p1->num,&p1->add);

}
p2->next=NULL;
return (head);
}

void fun2(struct student *head)
{
struct student *p;
p=head;
while(p!=NULL)
{
printf("%d %f\n",p->num,p->add);
p=p->next;
}
}
struct student *fun4(struct student *head,struct student *a)
{
struct student