当前位置:网站首页>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;
}
边栏推荐
- Adg5412fbruz-rl7 applies dual power analog switch and multiplexer IC
- Find the combination number acwing 888 Find the combination number IV
- Chinese remainder theorem acwing 204 Strange way of expressing integers
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- Modnet matting model reproduction
- confidential! Netease employee data analysis internal training course, white whoring! (attach a data package worth 399 yuan)
- 区间问题 AcWing 906. 区间分组
- Day 2 document
- Rehabilitation type force deduction brush question notes D1
- Game theory acwing 891 Nim games
猜你喜欢
7. Oracle table structure
Knapsack problem acwing 9 Group knapsack problem
Vscode creates its own code template
Find the combination number acwing 889 01 sequence meeting conditions
2.Oracle-数据文件的添加及管理
Rehabilitation type force deduction brush question notes D2
2. Addition and management of Oracle data files
Financial risk control practice -- feature derivation based on time series
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields
International Open Source firmware Foundation (osff) organization
随机推荐
Ffmpeg build download (including old version)
H5内嵌App适配暗黑模式
Winter vacation water test 1 Summary
'mongoexport 'is not an internal or external command, nor is it a runnable program or batch file.
How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
2022-5-the fourth week daily
背包问题 AcWing 9. 分组背包问题
Redis-02. Redis command
La redirection de l'applet Wechat ne déclenche pas onload
2022 winter vacation training game 5
1.手动创建Oracle数据库
PR automatically moves forward after deleting clips
Rehabilitation type force deduction brush question notes D2
P3265 [jloi2015] equipment purchase
AE tutorial - path growth animation
Record of problems in ollvm compilation
MySQL (UDF authorization)
Vant Weapp SwipeCell設置多個按鈕
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging