#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../include/list.h"
/**
* 将指定学生添加到链表中,尾端
* */
void append2list(NODE *list, STUDENT *student){
assert(student != NULL && list != NULL);
NODE *new_node = create_node(student);
//将当前链表的链表尾指向新的节点
//循环链表,找到尾节点
NODE *tail = list;
while(tail -> next != NULL){
//将tail指向tail的下一个节点
tail = tail -> next;
}
tail->next = new_node;
}
void print_student_line(STUDENT *student){
if(student == NULL){
return;
}
printf("|%-20s|%-20s|%-20d|\n", student -> no, student -> name, student -> gender);
}
/**
* 打印链表内容
* */
void print_list(NODE *list){
//表头
printf("|===================|===================|===================|\n");
printf("|%*s|%*s|%*s|\n", 20, "学号", 20, "姓名", 20, "性别");
NODE *cursor = list;
while (cursor != NULL)
{
print_student_line(cursor->student);
cursor = cursor -> next;
}
printf("|===================|===================|===================|\n");
}
/**
* 搜索学号
* */
STUDENT *search_list(NODE *list, char *no){
STUDENT *result = NULL;
NODE *cursor = list;
while( cursor != NULL){
if(cursor -> student != NULL && strcmp(cursor -> student -> no, no) == 0){
result = cursor -> student;
break;
}
cursor = cursor -> next;
}
return result;
}
/**
* 删除指定的学生信息
* */
void delete_from_list(NODE *list, STUDENT *student){
//待删除的节点
NODE *result = NULL;
NODE *cursor = list;
//当前节点的前一个节点
NODE *previous = NULL;
while( cursor != NULL){
if(cursor -> student != NULL && strcmp(cursor -> student -> no, student -> no) == 0){
//找到待删除的节点,将该节点的前一个节点的next指针,指向该节点的下一个节点
previous -> next = cursor -> next;
result = cursor;
break;
}
previous = cursor;
cursor = cursor -> next;
}
free(result);
}
/**
* 创建链表
* */
NODE *create_list(){
NODE *header = (NODE*)malloc(sizeof(NODE));
header -> next = NULL;
header -> student = NULL;
return header;
}
/**
* 计算链表的长度,节点数量
* */
unsigned int count_list(NODE *list){
int count = 0;
NODE *cursor = list;
while(cursor -> next != NULL){
cursor = cursor -> next;
count++;
}
return count;
}
基于C语言实现的学生信息管理系统,控制台应用.zip
版权申诉
145 浏览量
2024-01-11
10:16:34
上传
评论
收藏 9KB ZIP 举报
我慢慢地也过来了
- 粉丝: 6444
- 资源: 3991
最新资源
- vscode配置c/c 环境教程
- vscode配置c/c 环境教程
- 基于matlab实现电磁优化计算功能,进行线型规划优化电磁设计.rar
- 基于matlab实现带精英策略的非支配排序遗传算法matlab 源码.rar
- 基于matlab实现差分进化算法,最新的用于替代遗传算法,是以后的主要发展方法.rar
- VSCode配置c/c++环境教程.md
- 基于matlab实现标准合作型协同进化遗传算法matlab源程序
- 七下人教.zip
- 基于matlab实现本份代码能对图像进行gabor滤波处理,结合指纹方向图以及指纹沟壑频率特性,对指纹图像进行增强.rar
- 基于matlab实现RBM神经网络实现了手写数字体识别的GUI程序.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈