当前位置:网站首页>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 2sample 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;
}边栏推荐
- [Chongqing Guangdong education] National Open University 2018 autumn 0702-22t contemporary Chinese political system reference questions
- [2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
- RecyclerView的应用
- 3. Oracle control file management
- 容斥原理 AcWing 890. 能被整除的数
- Game theory acwing 892 Steps Nim game
- 区间问题 AcWing 906. 区间分组
- NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
- Sum of three terms (construction)
- The route of wechat applet jumps again without triggering onload
猜你喜欢
随机推荐
[learning] database: MySQL query conditions have functions that lead to index failure. Establish functional indexes
中国剩余定理 AcWing 204. 表达整数的奇怪方式
Relevant information of National Natural Science Foundation of China
5.Oracle-錶空間
微信小程序路由再次跳转不触发onload
2.Oracle-数据文件的添加及管理
RecyclerView的应用
June 29, 2022 daily
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
C Primer Plus Chapter 15 (bit operation)
Speedtree01 generator properties
[Gaode map POI stepping pit] amap Placesearch cannot be used
FFmpeg build下载(包含old version)
Getting started with typescript
Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter
TCP's understanding of three handshakes and four waves
求组合数 AcWing 887. 求组合数 III
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
ollvm编译出现的问题纪录
1.手动创建Oracle数据库









