当前位置:网站首页>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;
}
边栏推荐
- Client use of Argo CD installation
- 【LeetCode】Easy | 20. Valid parentheses
- 2.Oracle-数据文件的添加及管理
- [2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
- C job interview - casting and comparing - C job interview - casting and comparing
- Genesis builds a new generation of credit system
- Vant weave swipecell sets multiple buttons
- Some classic recursion problems
- 时间很快,请多做有意义的事情
- LeetCode-61
猜你喜欢
Vant Weapp SwipeCell设置多个按钮
LSA Type Explanation - detailed explanation of lsa-2 (type II LSA network LSA) and lsa-3 (type III LSA network Summary LSA)
Chinese remainder theorem acwing 204 Strange way of expressing integers
Use ffmpeg to rotate, flip up and down, and flip horizontally
Game theory acwing 891 Nim games
LSA Type Explanation - lsa-1 [type 1 LSA - router LSA] detailed explanation
What is socket? Basic introduction to socket
Interval problem acwing 906 Interval grouping
求组合数 AcWing 888. 求组合数 IV
Game theory acwing 894 Split Nim game
随机推荐
P2575 master fight
Vant weave swipecell sets multiple buttons
P3265 [jloi2015] equipment purchase
Redis-02. Redis command
Game theory acwing 893 Set Nim game
求组合数 AcWing 887. 求组合数 III
求组合数 AcWing 889. 满足条件的01序列
Niu Mei's math problems
区间问题 AcWing 906. 区间分组
微信小程序路由再次跳轉不觸發onload
Redis-01.初识Redis
vsCode创建自己的代码模板
2048 project realization
2048项目实现
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
Bit of MySQL_ OR、BIT_ Count function
Redis-02.Redis命令
H5 模块悬浮拖动效果
2. Addition and management of Oracle data files
Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams