下面展示一些 内联代码片
。
// A code block
var foo = 'bar';
// An highlighted block
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// 学生数据类型定义
typedef struct Student {
int id;
char name[50];
char course[50];
} Student;
// 顺序存储
Student students[100];
int studentCount = 0;
// 链式存储
typedef struct Node {
Student data;
struct Node *next;
struct Node* left;
struct Node* right;
} Node;
Node *head = NULL;
// 增加数据
void addStudent(int id, char name[], char course[]) {
Student newStudent;
newStudent.id = id;
strcpy(newStudent.name, name); // 使用strcpy将name字符串复制到newStudent.name中
strcpy(newStudent.course, course); // 使用strcpy将course字符串复制到newStudent.course中
students[studentCount++] = newStudent;
int main() {
int choice;
while (1) {
printf("****************************************************************\n");
printf("* 学生课程系统菜单 *\n");
printf("****************************************************************\n");
printf("* 1. 增加数据 *\n");
printf("* 2. 显示数据 *\n");
printf("* 3. 删除数据 *\n");
printf("* 4. 修改数据 *\n");
printf("* 5. 快速排序 *\n");
printf("* 6. 自选排序 *\n");
printf("* 7. 二叉排序树查找 *\n");
printf("* 8. 自选查找 *\n");
printf("* 0. 退出 *\n");
printf("****************************************************************\n");
printf("请选择功能:");
scanf("%d", &choice);
switch (choice) {
case 1: {
int id;
char name[50], course[50];
printf("输入学生ID: ");
scanf("%d", &id);
printf("输入姓名: ");
scanf("%s", name);
printf("输入课程: ");
scanf("%s", course);
addStudent(id, name, course);
break;
}
case 2: {
displayStudents();
break;
}
case 3: {
int id;
printf("输入要删除的学生ID: ");
scanf("%d", &id);
deleteStudent(id);
break;
}
case 4: {
int id;
char name[50], course[50];
printf("输入要修改的学生ID: ");
scanf("%d", &id);
printf("输入新的姓名: ");
scanf("%s", name);
printf("输入新的课程: ");
scanf("%s", course);
modifyStudent(id, name, course);
break;
}
case 5: {
clock_t start, end;
double timeUsed;
start = clock();
quickSort(students, 0, studentCount - 1);
end = clock();
timeUsed = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("快速排序时间复杂度: %f 秒\n", timeUsed);
break;
}
case 6: {
clock_t start, end;
double timeUsed;
start = clock();
customSort(students, studentCount);