#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define LEN sizeof(struct student) // student 结构的大小
struct student *creat();
struct student *del(struct student *head, int num);
void print(struct student *head);
struct student
{
int num;
float score;
struct student *next;
};
int n;
int main()
{
struct student *stu,*p;
int num;
stu=creat();
print( stu );
printf("\n\n输入要删除的学号:");
scanf("%d",&num);
printf("\n正在删除中......\n");
p=del(stu,num);
print( p );
printf("\n\n");
system("pause");
}
struct student *creat()
{
student *head;
struct student *p1, *p2;
p1=p2=(struct student *)malloc(LEN);
printf("Please enter the num :");
scanf("%d",&p1->num);
printf("Please enter the score :");
scanf("%f",&p1->score);
printf("\n\n");
head = NULL;
n=0;
while(p1->num)
{
n++;
if(1==n)
{
head = p1;
}else
{
p2->next=p1;
}
p2=p1;
p1=(struct student *)malloc(LEN);
printf("Please enter the num :");
scanf("%d",&p1->num);
printf("Please enter the score :");
scanf("%f",&p1->score);
printf("\n\n");
}
p2->next=NULL;
return head;
}
void print(struct student *head)
{
struct student *p;
printf("There are %d records.\n\n", n);
p=head;
do
{
printf("学号是 %d 的成绩是 %f.\n", p->num, p->score);
p=p->next;
}while(p);
}
struct student *del(struct student *head, int num)
{
struct student *p1,*p2;
if(NULL==head)
{
printf("It's nothing!Don't lie me.\n");
goto loop;
}
while(p1->num!=num&&p1->num==NULL)
{
p2=p1;
p1=p1->next;
}
if(p1->num==num)
{
if(head==p1)
{
head=p1->next;
}else
{
p2->next=p1->next;
}
printf("\n学号为%d的学生信息删除成功\n",num);
n-=1;
}else
{
printf("\n没有找到你要的thing\n");
}
loop: return head;
}
#include<stdlib.h>
#include<malloc.h>
#define LEN sizeof(struct student) // student 结构的大小
struct student *creat();
struct student *del(struct student *head, int num);
void print(struct student *head);
struct student
{
int num;
float score;
struct student *next;
};
int n;
int main()
{
struct student *stu,*p;
int num;
stu=creat();
print( stu );
printf("\n\n输入要删除的学号:");
scanf("%d",&num);
printf("\n正在删除中......\n");
p=del(stu,num);
print( p );
printf("\n\n");
system("pause");
}
struct student *creat()
{
student *head;
struct student *p1, *p2;
p1=p2=(struct student *)malloc(LEN);
printf("Please enter the num :");
scanf("%d",&p1->num);
printf("Please enter the score :");
scanf("%f",&p1->score);
printf("\n\n");
head = NULL;
n=0;
while(p1->num)
{
n++;
if(1==n)
{
head = p1;
}else
{
p2->next=p1;
}
p2=p1;
p1=(struct student *)malloc(LEN);
printf("Please enter the num :");
scanf("%d",&p1->num);
printf("Please enter the score :");
scanf("%f",&p1->score);
printf("\n\n");
}
p2->next=NULL;
return head;
}
void print(struct student *head)
{
struct student *p;
printf("There are %d records.\n\n", n);
p=head;
do
{
printf("学号是 %d 的成绩是 %f.\n", p->num, p->score);
p=p->next;
}while(p);
}
struct student *del(struct student *head, int num)
{
struct student *p1,*p2;
if(NULL==head)
{
printf("It's nothing!Don't lie me.\n");
goto loop;
}
while(p1->num!=num&&p1->num==NULL)
{
p2=p1;
p1=p1->next;
}
if(p1->num==num)
{
if(head==p1)
{
head=p1->next;
}else
{
p2->next=p1->next;
}
printf("\n学号为%d的学生信息删除成功\n",num);
n-=1;
}else
{
printf("\n没有找到你要的thing\n");
}
loop: return head;
}