数据结构--学生管理系统

一、底层数据结构选型

  1. 数组

◦ 优点:随机访问效率高,代码实现简单

◦ 缺点:固定长度,扩容需重新申请空间;增删元素要移动大量数据

◦ 适用场景:学生数量固定、查询操作频繁的场景

  1. 单链表

◦ 优点:动态扩容,增删操作无需移动大量元素,灵活性强

◦ 缺点:查询需遍历链表,效率较低;需额外存储节点指针

◦ 适用场景:学生数量动态变化、增删操作频繁的场景

二、核心功能模块

  1. 学生信息实体

包含学号(唯一标识)、姓名、年龄、专业等核心字段

  1. 核心操作

◦ 增加:添加前需校验学号唯一性,避免重复

◦ 删除:通过学号定位目标元素/节点,执行删除操作

◦ 修改:先按学号查询到目标,再更新对应信息

◦ 查询:支持按学号精准查询、按姓名模糊查询,以及遍历展示所有学生

三、Java 链表实现核心代码

// 学生实体类

class Student {

String id;

String name;

int age;

Student next;

public Student(String id, String name, int age) {

this.id = id;

this.name = name;

this.age = age;

}

}

// 学生管理系统类

public class StudentManager {

private Student head = new Student(null, null, 0); // 头结点

// 添加学生

public void addStudent(Student stu) {

Student temp = head;

while (temp.next != null) {

if (temp.next.id.equals(stu.id)) {

System.out.println("学号重复,添加失败");

return;

}

temp = temp.next;

}

temp.next = stu;

}

// 按学号删除学生

public void deleteStudent(String id) {

Student temp = head;

while (temp.next != null) {

if (temp.next.id.equals(id)) {

temp.next = temp.next.next;

System.out.println("删除成功");

return;

}

temp = temp.next;

}

System.out.println("未找到该学生");

}

// 遍历所有学生信息

public void showAll() {

Student temp = head.next;

if (temp == null) {

System.out.println("暂无学生信息");

return;

}

while (temp != null) {

System.out.println("学号:" + temp.id + " 姓名:" + temp.name + " 年龄:" + temp.age);

temp = temp.next;

}

}

// 主函数测试

public static void main(String[] args) {

StudentManager manager = new StudentManager();

manager.addStudent(new Student("001", "张三", 20));

manager.showAll();

manager.deleteStudent("001");

manager.showAll();

}

}

相关推荐
June bug1 小时前
【实习笔记】客户端基础技术
笔记·macos·cocoa
laplace01231 小时前
第八章 agent记忆与检索 下
数据库·人工智能·笔记·agent·rag
狐572 小时前
2026-01-19-牛客每日一题-阅读理解
笔记·算法·牛客
不会代码的小猴2 小时前
Linux环境编程第一天笔记
linux·笔记
航行的pig2 小时前
Python基础学习笔记
笔记·python
狐572 小时前
2026-01-19-论文阅读-AgiBot-1
论文阅读·笔记·具身智能
一分之二~2 小时前
回溯算法--解数独
开发语言·数据结构·c++·算法·leetcode
不如语冰3 小时前
AI大模型入门1.1-python基础-数据结构
数据结构·人工智能·pytorch·python·cnn
未来之窗软件服务3 小时前
计算机等级考试—哈希线性探测解答—东方仙盟
数据结构·哈希算法·散列表·计算机软考·仙盟创梦ide·东方仙盟
苦藤新鸡3 小时前
18.矩阵同行同列全置零
数据结构·c++·算法·力扣