d1.c:
#include<stdio.h>
#include"f1.h"
main()
{
struct stu *head;
int num;
head=creat();
list(head);
scanf("%d",&num);
head=del(head,num);
list(head);
}
d2.c:
#include<stdio.h>
#include<stdlib.h>
#include"f1.h"
#define LEN sizeof(struct stu )
struct stu *creat(void)
{
struct stu *p1,*p2;
struct stu *head=NULL;
p1=p2=(struct stu *)malloc(LEN);
scanf("%d%f%s",&p1->num,&p1->score,&p1->gender);
whil(p1->num!=0)
{
if(head==NULL)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct stu *)malloc(LEN);
scanf("%d%f%s",&p1->num,&p1->score,&p1->gender);
}
p2->next=NULL;
free(p1);
return head;
};
struct stu *del(struct stu *head,int num)
{
struct stu *p1,*p2;
p1=p2=(struct stu *)malloc(LEN);
if(head==NULL)
printf("Á´±íΪ¿Õ");
else
{
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
if(head=p1)
head=p1->next;
else
p2->next=p1->next;
}
}
free(p1);
return head;
};
void list(struct stu *head)
{
struct stu *p;
p=head;
while(p!=NULL)
{
printf("%d%f%s",p->num,p->score,p->gender);
p=p->next;
}
}
f1.h:
#ifndef f1_h
#define f1_h
struct stu
{
int num;
float score;
char gender[50];
struct stu *next;
};
struct stu *creat(void);
struct stu *del(struct stu *head,int num);
void list(struct stu *head);
#endif // f1_h
请在夏天叫醒我
相关分类