当前位置:网站首页>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;
}边栏推荐
- The route of wechat applet jumps again without triggering onload
- Time is fast, please do more meaningful things
- Paper reading report
- [2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
- Configuration method and configuration file of SolidWorks GB profile library
- Stack acwing 3302 Expression evaluation
- Adg5412fbruz-rl7 applies dual power analog switch and multiplexer IC
- How to answer when you encounter a jet on CSDN?
- Record the process of configuring nccl and horovod in these two days (original)
- ‘mongoexport‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
猜你喜欢

区间问题 AcWing 906. 区间分组

Vant weapp swippecell set multiple buttons

Game theory acwing 892 Steps Nim game

2. Addition and management of Oracle data files

背包问题 AcWing 9. 分组背包问题

Redis-01. First meet redis

高斯消元 AcWing 884. 高斯消元解异或线性方程组

论文阅读报告

ollvm编译出现的问题纪录

SolidWorks template and design library are convenient for designers to call
随机推荐
Game theory acwing 892 Steps Nim game
Application of recyclerview
ollvm编译出现的问题纪录
FFmpeg build下载(包含old version)
Ffmpeg build download (including old version)
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
7.Oracle-表结构
Paper reading report
2022 winter vacation training game 5
Configuration method and configuration file of SolidWorks GB profile library
求组合数 AcWing 889. 满足条件的01序列
P3265 [jloi2015] equipment purchase
There are three kinds of SQL connections: internal connection, external connection and cross connection
H5 embedded app adapts to dark mode
Use ffmpeg to rotate, flip up and down, and flip horizontally
Vant Weapp SwipeCell設置多個按鈕
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
June 29, 2022 daily
高斯消元 AcWing 884. 高斯消元解异或線性方程組
Record of problems in ollvm compilation