当前位置:网站首页>6-3 find the table length of the linked table
6-3 find the table length of the linked table
2022-07-07 22:45:00 【Qingshan's green shirt】
Function interface definition :`
int Length( List L );
among List The structure is defined as follows
typedef struct LNode *PtrToLNode;
struct LNode {
ElementType Data;
PtrToLNode Next;
};
typedef PtrToLNode List;
L Is a given single linked list , function Length To return the length of the linked list .
Sample referee test procedure :
#include <stdio.h>
#include <stdlib.h>
typedef int ElementType;
typedef struct LNode *PtrToLNode;
struct LNode {
ElementType Data;
PtrToLNode Next;
};
typedef PtrToLNode List;
List Read(); /* Details are not shown here */
int Length( List L );
int main()
{
List L = Read();
printf("%d\n", Length(L));
return 0;
}
/* Your code will be embedded here */
Ideas
Create a pointer p, Used to traverse a linked list . Create a counter , For statistical length .
Specific code implementation
int Length( List L )
{
List p; // The pointer p, Notice that it's not List*!!!!!!!!
p = L;
int j = 0;
while( p)
{
j++;
p = p->Next;
}
return j;
}
Some of my questions
1. At first, the compilation error is because it is always written List *p!! Still don't understand structure and typedef Usage of !
2021.10.05
21:22
边栏推荐
- ASP. Net core introduction V
- C development - interprocess communication - named pipeline
- 微服務遠程Debug,Nocalhost + Rainbond微服務開發第二彈
- Firefox browser installation impression notes clipping
- 如何选择合适的自动化测试工具?
- Use partial derivatives to display normals in unity
- 「开源摘星计划」Loki实现Harbor日志的高效管理
- 详解全志V853上的ARM A7和RISC-V E907之间的通信方式
- php 获取图片信息的方法
- Attitude estimation (complementary filtering)
猜你喜欢
[problem] pytorch installation
How to judge whether the input content is "number"
php 获取图片信息的方法
数字化转型:五个步骤推动企业进步
Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
How pyGame rotates pictures
Implementation method of data platform landing
Yarn开启ACL用户认证之后无法查看Yarn历史任务日志解决办法
Remember aximp once Use of exe tool
The whole network "chases" Zhong Xuegao
随机推荐
Take full control! Create a "leading cockpit" for smart city construction
Attitude estimation (complementary filtering)
怎样写一个增广矩阵到txt文件中
Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
Welcome to CSDN markdown editor
Aspose. Words merge cells
[problem] pytorch installation
Revit secondary development - get the thickness / length / height of the beam
Revit secondary development - intercept project error / warning pop-up
Remove the default background color of chrome input input box
[azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process
Paint basic graphics with custompaint
Record problems fgui tween animation will be inexplicably killed
Redis official ORM framework is more elegant than redistemplate
PHP records the pitfalls encountered in the complete docking of Tencent cloud live broadcast and im live group chat
php 记录完整对接腾讯云直播以及im直播群聊 所遇到的坑
Add get disabled for RC form
Ni9185 and ni9234 hardware settings in Ni Max
How to close eslint related rules
[azure microservice service fabric] the service fabric cluster hangs up because the certificate expires (the upgrade cannot be completed, and the node is unavailable)