c语言学生成绩管理系统按照学号排序怎么排
发布网友
发布时间:2022-05-27 14:07
我来回答
共2个回答
热心网友
时间:2023-10-27 04:07
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student
{
char name[12];
char student_id[12];
unsigned short Chinese;
unsigned short English;
unsigned short Math;
unsigned short average;
}student_t;
unsigned short num;
unsigned short pass_rate;
void enter_message(student_t *p);
void sort(student_t *p);
void print_message(student_t *p);
void swit_student(student_t *p,student_t *q);
int main(int argc, char const *argv[])
{
printf("Enter the number of students:");
scanf("%hu",&num);
student_t *p = NULL;
p = (student_t *)malloc(num * sizeof(student_t));
printf("Enter students message,example: name student_id Chinese English Math\n");
enter_message(p);
sort(p);
print_message(p);
free(p);
return 0;
}
unsigned short num;
unsigned short pass_rate;
void enter_message(student_t *p);
void sort(student_t *p);
void print_message(student_t *p);
void swit_student(student_t *p,student_t *q);
int main(int argc, char const *argv[])
{
printf("Enter the number of students:");
scanf("%hu",&num);
student_t *p = NULL;
p = (student_t *)malloc(num * sizeof(student_t));
printf("Enter students message,example: name student_id Chinese English Math\n");
enter_message(p);
sort(p);
print_message(p);
free(p);
return 0;
}
void swit_student(student_t *p,student_t *q)
{
student_t temp;
strcpy(temp.name,p->name);
strcpy(p->name,q->name);
strcpy(q->name,temp.name);
strcpy(temp.student_id,p->student_id);
strcpy(p->student_id,q->student_id);
strcpy(q->student_id,temp.student_id);
temp.Chinese = p->Chinese;
p->Chinese = q->Chinese;
q->Chinese = temp.Chinese;
temp.English = p->English;
p->English = q->English;
q->English = temp.English;
temp.Math = p->Math;
p->Math = q->Math;
q->Math = temp.Math;
temp.average = p->average;
p->average = q->average;
q->average = temp.average;
}
热心网友
时间:2023-10-27 04:07
排序有很多种实现方法,效率较低(但比较容易理解)的有选择排序、插入排序、冒泡排序、鸡尾酒排序等,效率较高的有希尔排序、堆排序、快速排序、归并排序等。作为一个应用系统,可以不必自己写排序的实现算法,直接调用C标准的快速排序函数qsort,但前提是给出一个比较规则函数,说明数组中两个元素如何判断大小(是按照数值比较还是字符串比较等等),然后在qsort的第四个参数中使用这个规则函数。