#include <stdio.h> #include <stdlib.h> #include <string.h>

typedef struct Student { int sno; char name[10]; char sex; int age; } Student;

typedef struct Table { Student stu[10001]; int num; } Table;

int main() { Table table; int n; scanf("%d", &n); table.num = n; for (int i = 0; i < n; i++) { scanf("%d %s %c %d", &table.stu[i].sno, table.stu[i].name, &table.stu[i].sex, &table.stu[i].age); } Student newStu; scanf("%d %s %c %d", &newStu.sno, newStu.name, &newStu.sex, &newStu.age); int i; for (i = 0; i < table.num; i++) { if (newStu.sno < table.stu[i].sno) { for (int j = table.num - 1; j >= i; j--) { table.stu[j + 1] = table.stu[j]; } table.stu[i] = newStu; table.num++; break; } } if (i == table.num) { table.stu[table.num] = newStu; table.num++; } printf("插入后的学生信息:\n"); for (int i = 0; i < table.num; i++) { printf("%d %s %c %d\n", table.stu[i].sno, table.stu[i].name, table.stu[i].sex, table.stu[i].age); } return 0; }

C语言实现学生信息插入排序算法

原文地址: https://www.cveoy.top/t/topic/ojKo 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录