单链表文件版图书管理系统

本文介绍了使用链表作为数据结构来实现一个文件版图书管理系统的逻辑。通过链表,可以快速进行书籍数据的插入和删除操作,且链表在堆区分配内存,理论上无存储上限限制。此外,链表在文件操作中具有优势,便于系统管理。
摘要由CSDN通过智能技术生成

文件操作,链表操作,管理系统

在这里插入图片描述
运行截图,
在这里插入图片描述

文件储存
在这里插入图片描述
逻辑详解,
1,为什么写在这个要用链表,
1.1,链表的插入和删除 速度相比数组来说,速度快,我们操作书籍数据,不停的的插入课删除,
1.2, 链表的数据都在堆区开辟,理论上讲链表没有尽头,所以不会限制你的系统存储的书籍上限
1.3,整个链表只有一个指针指向的地址去存储数据,所以操作比较方便尤其是文件操作

代码区

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <list>
using namespace std;

//3.数据的设计?
	//3.1 程序用什么东西处理数据---->容器--->链表
	//3.2 数据的结构  ---->图书的信息
struct bookInfo 
{
   
	char name[20];   //书名
	float price;	 //书籍的价格
	int num;		 //书的数量
};
struct Node 
{
   
	struct bookInfo data;
	struct Node* next;
};
struct Node* listBook = NULL;
//创建表头: 表头就是一个结构体变量

//另一个部分:用户信息
struct student 
{
   
	char name[20];
	char tel[20];
	int curNum;
	struct bookInfo userBook[3];
};
list<student> myList;



struct Node* createHead() 
{
   
	//动态内存申请
	struct Node* headNode = (struct Node*)malloc(sizeof(struct Node));
	//变量的基本规则>? 使用前必须初始化
	headNode->next = NULL;
	return headNode;
}

//创建节点: 为插入做准备
//把用户的数据变为结构体变量
struct Node* createNode(struct bookInfo  data)
{
   
	struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
	newNode->data = data;
	newNode->next = NULL;
	return newNode;
}
//插入:只需要一种插入方式
void insertNodeByHead(struct Node* headNode, struct bookInfo  data)
{
   
	struct Node* newNode = createNode(data);
	//必须先连接后断开
	newNode->next = headNode->next;
	headNode->next = newNode;
}
//指定删除
//posLeftNode->next=posNode->next;
//free(posNode);
void deleteNodeByName(struct Node* headNode, char *bookName) 
{
   
	struct Node
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

c语言,c++

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

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

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

打赏作者

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

抵扣说明:

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

余额充值