C语言完整代码学生课程系统加文档,制作不易,勿白嫖

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
下面展示一些 内联代码片

部分源码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>


//企鹅联系-----------------3765140556 


// 学生数据类型定义
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;

    // 链式存储
    Node *newNode = (Node *)malloc(sizeof(Node));
    newNode->data = newStudent;
    newNode->next = head;
    head = newNode;
}


// 显示数据
void displayStudents() {
    printf("顺序存储:\n");
    for (int i = 0; i < studentCount; i++) {
        printf("ID: %d, Name: %s, Course: %s\n", students[i].id, students[i].name, students[i].course);
    }

    printf("\n链式存储:\n");
    Node *current = head;
    while (current != NULL) {
        printf("ID: %d, Name: %s, Course: %s\n", current->data.id, current->data.name, current->data.course);
        current = current->next;
    }
}

// 删除数据
void deleteStudent(int id) {
    for (int i = 0; i < studentCount; i++) {
        if (students[i].id == id) {
            for (int j = i; j < studentCount - 1; j++) {
                students[j] = students[j + 1];
            }
            studentCount--;
            break;
        }
    }

    // 链式存储
    Node *current = head;
    Node *prev = NULL;
    while (current != NULL) {
        if (current->data.id == id) {
            if (prev == NULL) {
                head = current->next;
            } else {
                prev->next = current->next;
            }
            free(current);
            break;
        }
        prev = current;
        current = current->next;
    }
}

// 修改数据
void modifyStudent(int id, char name[], char course[]) {
    for (int i = 0; i < studentCount; i++) {
        if (students[i].id == id) {
            strcpy(students[i].name, name);
            strcpy(students[i].course, course);
            break;
        }
    }

    // 链式存储
    Node *current = head;
    while (current != NULL) {
        if (current->data.id == id) {
            strcpy(current->data.name, name);
            strcpy(current->data.course, course);
            break;
        }
        current = current->next;
    }
}


// 快速排序
int partition(Student arr[], int low, int high) {
    Student pivot = arr[high];
    int i = low - 1;
    for (int j = low; j < high; j++) {
        if (arr[j].id < pivot.id) {
            i++;
            Student temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
    }
    Student temp = arr[i + 1];
    arr[i + 1] = arr[high];
    arr[high] = temp;
    return i + 1;
}

void quickSort(Student arr[], int low, int high) {
    if (low < high) {
        int pi = partition(arr, low, high);
        quickSort(arr, low, pi - 1);
        quickSort(arr, pi + 1, high);
    }
}
// 冒泡排序算法

void customSort(Student arr[], int n) {
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (arr[j].id > arr[j + 1].id) {
                Student temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }
}

// 二叉排序树查找
Node* insertBST(Node* root, Student data) {
    if (root == NULL) {
        Node* newNode = (Node*)malloc(sizeof(Node));
        newNode->data = data;
        newNode->left = NULL;
        newNode->right = NULL;
        return newNode;
    }

    if (data.id < root->data.id) {
        root->left = insertBST(root->left, data);
    } else if (data.id > root->data.id) {
        root->right = insertBST(root->right, data);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

徐瑶万正源码,可堪头相,徐福费

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

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

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

打赏作者

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

抵扣说明:

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

余额充值