结构体记录学生信息并找出最高成绩并删除后输出

#include<stdio.h>
#include<stdlib.h>
#define N 2
struct stu
{
	int num;
	char name[10];
	int gra;
	struct student *next;
};
int main()
{
	struct stu *creat(struct stu *head,int n);
	struct stu *findmax(struct stu *head);
	struct stu *dele(struct stu *head,int x);
	void print(struct stu *head);
	int max;
	struct stu *head=NULL;
	head=creat(head,N);
	print(head);
	max=findmax(head);
	head=dele(head,max);
	printf("删除后");
	print(head);
	return 0;
}
struct stu *creat(struct stu *head,int n)
{
	struct stu *p,*q;
	int i;
	for(i=0;i<n;i++)
	{
		q=(struct stu * )malloc(sizeof(struct stu));
		printf("请输入第%d名学生的学号姓名和成绩\n",i+1);
		scanf("%d%s%d",&q->num,&q->name,&q->gra);
		q->next=NULL;
		if(head==NULL)
			head=q;
		else
			p->next=q;
		p=q;
	}
	return head;
}
void print(struct stu *head)
{
	struct stu *p=head;
	printf("学生信息为\n");
	while(p!=NULL)
	{
		printf("%d %s %d\n",p->num,p->name,p->gra);
		p=p->next;
	}
}
struct stu *dele(struct stu *head,int x)
{
	struct stu *p,*q;
	p=head;
	while(p!=NULL&&p->gra!=x)
	{
		q=p;
		p=p->next;
	}
	if(p==head)
		head=p->next;
	else
		q->next=p->next;
	free(p);
	return head;
}
struct stu *findmax(struct stu *head)
{
	struct stu *p;
	int max=0;
	p=head;
	while(p!=NULL)
	{
		if(p->gra>max)
		{
			max=p->gra;
		}
		p=p->next;
	}
	printf("最高成绩为%d\n",max);
	return max;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

iKUNqa

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值