当前位置:网站首页>单向链表实现--计数
单向链表实现--计数
2022-06-23 11:03:00 【jinxueHou专栏】
单向链表和计量统计函数实现:
int16_t SingLinkList_Traverse(BOOKLT *bookHeadNode)
{
int16_t num = 0;//统计图书数量
BOOKLT * p = NULL; //创建一个BOOKLT结构类型的指针
p = bookHeadNode->next; //p指向头结点的next
if(NULL == p->next)//只有头结点
{
return -1;
}
while(p)//p->next不为空,继续遍历
{
printf("%s,%s,%d\r\n",p->bookInfo.ISBN,p->bookInfo.bookName,p->bookInfo.price);//输出每个结点的数据域内容
p = p->next;//指向下一个结点
num++; //遍历一个结点,数量加1
}
return num;
}main.c函数实现如下:
int main()
{
int16_t num = 0;
BOOKLT *myBookHeadNode;//定义一个BOOKLT类型的头结点指针
myBookHeadNode = SingLinkList_Create();//上面的链表内存已经被释,重新放创建一个头结点
SingLinkList_TailInsert_method2(myBookHeadNode,sizeof(bookStock)/sizeof(BOOKINFO),bookStock);//后插法插入节点
SingLinkList_SelectSort(myBookHeadNode);//选择排序调用
num = SingLinkList_Traverse(myBookHeadNode);//遍历单向链表和统计图书数量
printf("\r\n图书数量为:%d\r\n",num);
SingLinkList_Destory(myBookHeadNode);//释放各个结点的内存和头结点的内存
return 0;
}图书信息和图书计量如下:

至此,单向链表统计图书数量功能已实现。
2022.06.19结。
边栏推荐
- 【MATLAB 图形用户界面控件使用】
- Why should poll/select use Nonblock when opening
- Unity technical manual - limit velocity over lifetime sub module and inherit velocity sub module
- list的介绍及使用
- 从0到1,IDE如何提升端侧研发效率?| DX研发模式
- Deep dive kotlin synergy (XIV): problems of shared state
- 开源二进制文件静态漏洞分析工具BinAbsInspector安装使用
- web技术分享| 【高德地图】实现自定义的轨迹回放
- Design and implementation of stm32f103zet6 single chip microcomputer dual serial port mutual sending program
- Noi OJ 1.3 15: apple and bug C language
猜你喜欢

Unity technical manual - limit velocity over lifetime sub module and inherit velocity sub module

Analysis of LinkedList source code

After repeated pressure, Apple may significantly increase the price of iphone14

What does NFTs, Web3 and metauniverse mean for digital marketing?

【ML】QuantileRegressor

最简单DIY基于C#和51单片机上下位机一体化的PCA9685舵机控制程序

Design and implementation of stm32f103zet6 single chip microcomputer dual serial port mutual sending program

最简单DIY串口蓝牙硬件实现方案

最简单DIY基于STM32的远程控制电脑系统①(电容触摸+按键控制)

Explain in detail the method of judging the size end
随机推荐
UWA new | real person real machine test new overseas model zone
如何用 Redis 实现一个分布式锁
A child process is created in the program, and then the parent and child processes run independently. The parent process reads lowercase letters on the standard input device and writes them to the pip
5 login failures, limiting login practice
Not satisfied with the effect of the smart park? Please accept this secret script of thingjs
php反射类使用
The simplest DIY pca9685 steering gear control program based on the integration of upper and lower computers of C # and 51 single chip microcomputer
Google Earth Engine(GEE)——GEDI L2A Vector Canopy Top Height (Ver
华为云·维享会交流平台简介
NOI OJ 1.2 整型与布尔型的转换 C语言
JVM easy start-02
圖片存儲--引用
Design and implementation of stm32f103zet6 single chip microcomputer dual serial port mutual sending program
MAUI使用Masa blazor组件库
The problem of C language structure byte alignment
Argmax function notes - full of details
Economic common sense
Simplest DIY remote control computer system based on STM32 ① (capacitive touch + key control)
Picture storage -- Reference
韦东山设备信息查询例程学习