栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux 使用尾插法实现 链表A每个节点存放一个新的链表B1B2,B3,B4,B5的头结点。场景:一个年级相当链表A该年级5个班,每个班5个人,做学生管理系统源代码

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux 使用尾插法实现 链表A每个节点存放一个新的链表B1B2,B3,B4,B5的头结点。场景:一个年级相当链表A该年级5个班,每个班5个人,做学生管理系统源代码

#include 
#include 

struct Student
{
	int yuwen;
	int shuxue;
	int yingyu;
	int ban;
	int ji;
	int zf;
	struct Student *next;
};

struct Class
{
	struct Student *xnext;
	struct Class *next;
};

void wellcome()
{
	printf("*************************************************************n");
	printf("*************************************************************n");
	printf("*************************************************************n");
	printf("**********wellcome to the Student Management System**********n");
	printf("*************************************************************n");
    printf("*************************************************************n");
    printf("*************************************************************n");
}

struct Class *bjsf(struct Class *head,struct Class *new)
{
	struct Class *p=head;
	if(p == NULL){
		head=new;
		return head;
	}
	while(p->next != NULL){
		p=p->next;
	}
	p->next=new;
	return head;
}

struct Student *xssf(struct Student *head,struct Student *new)
{
	struct Student *p=head;
	if(p ==NULL){
		head=new;
		return head;
	}
	while(p->next != NULL){
		p=p->next;
	}
	p->next=new;
	return head;
}

struct Student *xs(struct Student *xshead,int i)
{
	struct Student *new=NULL;
	int j;
	for(j=0;j<5;j++){
		new=(struct Student *)malloc(sizeof(struct Student));
		printf("please input %dclass %dge Student yuwen scoren",i+1,j+1);
		scanf("%d",&(new->yuwen));
		while(new->yuwen < 0  || new->yuwen > 100){
			printf("NO INPUTn");
			scanf("%d",&(new->yuwen));
		}
		
		printf("please input %dclass %dge Student shuxue scoren",i+1,j+1);
                scanf("%d",&(new->shuxue));
                while(new->shuxue < 0  || new->shuxue > 100){
                        printf("NO INPUTn");
                        scanf("%d",&(new->shuxue));
                }
		
		printf("please input %dclass %dge Student english scoren",i+1,j+1);
                scanf("%d",&(new->yingyu));
                while(new->yingyu < 0  || new->yingyu > 100){
                        printf("NO INPUTn");
                        scanf("%d",&(new->yingyu));
                }
		new->ban=i;
		new->ji=j;
		new->zf=new->yuwen+new->shuxue+new->yingyu;
		xshead=xssf(xshead,new);
	}
	return xshead;
}

struct Class *banji(struct Class *bjhead)
{
	struct Class *new=NULL;
	struct Student *xshead=NULL;
	int i;
	for(i=0;i<5;i++){
		new=(struct Class *)malloc(sizeof(struct Class));
		xshead=xs(xshead,i);
		new->xnext=xshead;
		bjhead=bjsf(bjhead,new);
	}
	return bjhead;
}

void printflink(struct Class *head)
{
	struct Student *xhead=NULL;
	xhead=head->xnext;
	int i,j;
	for(i=0;i<5;i++){
		for(j=0;j<5;j++){
			printf("%dclass%dstudent yuwen=%dn",i+1,j+1,xhead->yuwen);
			printf("%dclass%dstudent shuxue=%dn",i+1,j+1,xhead->shuxue);
			printf("%dclass%dstudent yingyu=%dn",i+1,j+1,xhead->yingyu);
			xhead=xhead->next;
			putchar('n');
		}
		head=head->next;
	}
}

void findmax(struct Class *head)
{
	int max;
	int i=0;
	int j=0;
	struct Student *xhead=NULL;
	xhead=head->xnext;
	max=xhead->zf;
	while(head != NULL){
		while(xhead != NULL){
			if(max < xhead->zf){
				max=xhead->zf;
				i=xhead->ban;
				j=xhead->ji;
			}
			xhead=xhead->next;
		}
		head=head->next;
	}
	printf("max student from %dban%dge Student score sum=%dn",i+1,j+1,max);
}

void findmin(struct Class *head)
{
       	int min;
        int i=0;
        int j=0;
        struct Student *xhead=NULL;
        xhead=head->xnext;
        min=xhead->zf;
        while(head != NULL){
                while(xhead != NULL){
                        if(min > xhead->zf){
                                min=xhead->zf;
                                i=xhead->ban;
                                j=xhead->ji;
                        }
                        xhead=xhead->next;
                }
                head=head->next;
        }
        printf("min Student from  %dban%dge Student score sum=%dn",i+1,j+1,min);

}

void findpz(struct Class *head)
{
	double sum=0;
	struct Student *xhead=NULL;
	xhead=head->xnext;
	while(head != NULL){
		while(xhead != NULL){
			sum+=xhead->zf;
			xhead=xhead->next;
		}
		head=head->next;
	}
	printf("Student  zf=%.0lfn",sum);
	printf("Student  pj=%.2fn",(float)sum/25);
}

int main()
{
	struct Class *head=NULL;
		
	wellcome();//欢迎界面
		
	head=banji(head);//建立班级链表
	
	printflink(head);//打印刚才输入的成绩
	
	findmax(head);//找到三门功课最高分
	
	findmin(head);//找到三门功课最低分
	
	findpz(head);//找到代码平均分和总分
	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/510105.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号