当前位置:网站首页>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;
}
边栏推荐
- Find the combination number acwing 888 Find the combination number IV
- Huawei bracelet, how to add medicine reminder?
- 2048 project realization
- H5 模块悬浮拖动效果
- 背包问题 AcWing 9. 分组背包问题
- 1. Create Oracle database manually
- LSA Type Explanation - lsa-1 [type 1 LSA - router LSA] detailed explanation
- Knapsack problem acwing 9 Group knapsack problem
- Rehabilitation type force deduction brush question notes D1
- 【LeetCode】Easy | 20. Valid parentheses
猜你喜欢
【高德地图POI踩坑】AMap.PlaceSearch无法使用
[algorithm post interview] interview questions of a small factory
Chapter 6 relational database theory
confidential! Netease employee data analysis internal training course, white whoring! (attach a data package worth 399 yuan)
Single chip computer engineering experience - layered idea
5.Oracle-表空间
There are three kinds of SQL connections: internal connection, external connection and cross connection
‘mongoexport‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
4.Oracle-重做日志文件管理
随机推荐
2.Oracle-数据文件的添加及管理
Find the combination number acwing 889 01 sequence meeting conditions
Nested method, calculation attribute is not applicable, use methods
Winter messenger 2
2022/6/29-日报
11-gorm-v2-02-create data
Design specification for mobile folding screen
AE tutorial - path growth animation
Financial risk control practice -- feature derivation based on time series
Dataframe (1): introduction and creation of dataframe
Inclusion exclusion principle acwing 890 Divisible number
MQClientException: No route info of this topic: type_ topic
The “mode“ argument must be integer. Received an instance of Object
[BMZCTF-pwn] ectf-2014 seddit
[wustctf2020] plain_ WP
Relevant information of National Natural Science Foundation of China
LeetCode-54
高斯消元 AcWing 884. 高斯消元解异或線性方程組
11-gorm-v2-03-basic query
高斯消元 AcWing 884. 高斯消元解异或线性方程组