#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//3.数据的设计
//3.1程序的数据存储--->容器
//3.2数据的结构 --->图书的信息
struct bookInfo
{
char name[20]; //书名
float price; //书籍的价格
int num; //书籍的数量
};
//定义链表
struct Node
{
struct bookInfo data;
struct Node* next;
};
struct Node* list = NULL; //将链表声明成全局变量
//创建表头:表头就是结构体变量
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;
}
//尾插法
/*struct insertNodeByTall(struct Node* headNode, int data)
{
struct Node* pMove = headNode;
while (pMove != NULL)
{
pMove = pMove->next;
}
struct Node* newNode = createHead(data);
pMove->next = newNode;