当前位置:网站首页>6-4 search by serial number of linked list
6-4 search by serial number of linked list
2022-07-05 06:37:00 【timingzj】
This question requests to realize a function , Find and return the second row of the linked list K Elements .
Function interface definition :
ElementType FindKth( List L, int K );
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 FindKth
To return the second K
Elements . If the element doesn't exist , Then return to ERROR
.
Sample referee test procedure :
#include <stdio.h>
#include <stdlib.h>
#define ERROR -1
typedef int ElementType;
typedef struct LNode *PtrToLNode;
struct LNode {
ElementType Data;
PtrToLNode Next;
};
typedef PtrToLNode List;
List Read(); /* Details are not shown here */
ElementType FindKth( List L, int K );
int main()
{
int N, K;
ElementType X;
List L = Read();
scanf("%d", &N);
while ( N-- ) {
scanf("%d", &K);
X = FindKth(L, K);
if ( X!= ERROR )
printf("%d ", X);
else
printf("NA ");
}
return 0;
}
/* Your code will be embedded here */
sample input :
1 3 4 5 2 -1
6
3 6 1 5 4 2
sample output :
4 NA 1 2 5 3
Code :
ElementType FindKth( List L, int K )
{
int i = 1;
while(L)
{
if(i == K)
return L->Data;
L = L->Next;
i++;
}
return ERROR;
}
边栏推荐
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- 代码中的英语全部
- Chinese remainder theorem acwing 204 Strange way of expressing integers
- P3265 [jloi2015] equipment purchase
- LSA Type Explanation - lsa-1 [type 1 LSA - router LSA] detailed explanation
- 3.Oracle-控制文件的管理
- Adg5412fbruz-rl7 applies dual power analog switch and multiplexer IC
- 区间问题 AcWing 906. 区间分组
- AE tutorial - path growth animation
- 微信小程序路由再次跳转不触发onload
猜你喜欢
什么是套接字?Socket基本介绍
Chinese remainder theorem acwing 204 Strange way of expressing integers
安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
There are three kinds of SQL connections: internal connection, external connection and cross connection
Client use of Argo CD installation
Interval problem acwing 906 Interval grouping
What is socket? Basic introduction to socket
'mongoexport 'is not an internal or external command, nor is it a runnable program or batch file.
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
随机推荐
什么是套接字?Socket基本介绍
Redis-01. First meet redis
Configuration method and configuration file of SolidWorks GB profile library
MPLS experiment
Utf8 encoding
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields
H5 module suspension drag effect
2. Addition and management of Oracle data files
SolidWorks template and design library are convenient for designers to call
Genesis builds a new generation of credit system
Presentation of attribute value of an item
SQL三种连接:内连接、外连接、交叉连接
Rehabilitation type force deduction brush question notes D1
June 29, 2022 daily
Interval problem acwing 906 Interval grouping
容斥原理 AcWing 890. 能被整除的数
Sum of three terms (construction)
our solution
Nested method, calculation attribute is not applicable, use methods
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore