商家入驻
发布需求

学生管理系统实现:C语言单链表功能详解

   2025-07-07 9
导读

学生管理系统是高校或教育机构常用的一种管理工具,用于记录和管理学生的基本信息。在实现学生管理系统时,我们通常会使用C语言来实现单链表的功能。以下是一个简单的C语言实现学生管理系统的示例代码。

学生管理系统是高校或教育机构常用的一种管理工具,用于记录和管理学生的基本信息。在实现学生管理系统时,我们通常会使用C语言来实现单链表的功能。以下是一个简单的C语言实现学生管理系统的示例代码:

```c

#include

#include

typedef struct Node {

int id; // 学生ID

char name[20]; // 学生姓名

int age; // 学生年龄

struct Node *next; // 指向下一个节点的指针

} Student;

// 创建新节点

Student *createNode(int id, char name[], int age) {

Student *newNode = (Student *)malloc(sizeof(Student));

if (newNode == NULL) {

printf("内存分配失败!

");

exit(1);

}

newNode->id = id;

strcpy(newNode->name, name);

newNode->age = age;

newNode->next = NULL;

return newNode;

}

// 插入新节点到链表尾部

void insertNode(Student *head, int id, char name[], int age) {

Student *newNode = createNode(id, name, age);

if (head == NULL) {

head = newNode;

} else {

Student *temp = head;

while (temp->next != NULL) {

temp = temp->next;

}

temp->next = newNode;

}

}

// 删除链表中指定ID的学生

void deleteNode(Student *head, int id) {

Student *temp = head;

学生管理系统实现:C语言单链表功能详解

while (temp != NULL && temp->id != id) {

temp = temp->next;

}

if (temp == NULL) {

printf("未找到该学生!

");

return;

}

if (temp->next != NULL) {

Student *prev = temp->next;

prev->next = temp->next->next;

} else {

head = temp->next;

}

free(temp);

}

// 打印所有学生信息

void printAllStudents(Student *head) {

Student *temp = head;

while (temp != NULL) {

printf("ID: %d, Name: %s, Age: %d

", temp->id, temp->name, temp->age);

temp = temp->next;

}

}

int main() {

// 创建一个空链表

Student *head = NULL;

// 添加学生信息

insertNode(head, 1, "张三", 20);

insertNode(head, 2, "李四", 22);

insertNode(head, 3, "王五", 21);

// 打印所有学生信息

printAllStudents(head);

// 删除学生信息

deleteNode(head, 2);

// 再次打印所有学生信息

printAllStudents(head);

return 0;

}

```

这个示例代码实现了一个简单的学生管理系统,包括创建新节点、插入新节点、删除指定ID的学生和打印所有学生信息等功能。通过这个系统,我们可以方便地管理和查询学生信息。

 
举报收藏 0
免责声明
• 
本文内容部分来源于网络,版权归原作者所有,经本平台整理和编辑,仅供交流、学习和参考,不做商用。转载请联系授权,并注明原文出处:https://www.itangsoft.com/baike/show-2462303.html。 如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除。涉及到版权或其他问题,请及时联系我们处理。
 
 
更多>热门产品
蓝凌MK 蓝凌MK

130条点评 4.5星

办公自动化

简道云 简道云

0条点评 4.5星

低代码开发平台

帆软FineBI 帆软FineBI

0条点评 4.5星

商业智能软件

纷享销客CRM 纷享销客CRM

0条点评 4.5星

客户管理系统

悟空CRM 悟空CRM

113条点评 4.5星

客户管理系统

钉钉 钉钉

0条点评 4.6星

办公自动化

金蝶云星空 金蝶云星空

0条点评 4.4星

ERP管理系统

用友YonBIP 用友YonBIP

0条点评 4.5星

ERP管理系统

唯智TMS 唯智TMS

113条点评 4.6星

物流配送系统

蓝凌EKP 蓝凌EKP

0条点评 4.5星

办公自动化

 
 
更多>同类知识

发需求

免费咨询专家帮您选产品

找客服

客服热线:177-1642-7519

微信扫码添加

小程序

使用小程序 查找更便捷

微信扫码使用

公众号

关注公众号 消息更及时

微信扫码关注

顶部