当前位置:网站首页>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;
}边栏推荐
- [QT] QT multithreading development qthread
- Stack acwing 3302 Expression evaluation
- ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
- How to correctly ask questions in CSDN Q & A
- 博弈论 AcWing 892. 台阶-Nim游戏
- ollvm编译出现的问题纪录
- Redis-02.Redis命令
- LSA Type Explanation - lsa-1 [type 1 LSA - router LSA] detailed explanation
- 2. Addition and management of Oracle data files
- [Chongqing Guangdong education] National Open University 2018 autumn 0702-22t contemporary Chinese political system reference questions
猜你喜欢

Chapter 6 relational database theory

20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore

How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling

代码中的英语全部

Some classic recursion problems

求组合数 AcWing 888. 求组合数 IV

什么是套接字?Socket基本介绍

Simple selection sort of selection sort

3. Oracle control file management

容斥原理 AcWing 890. 能被整除的数
随机推荐
How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
C Primer Plus Chapter 15 (bit operation)
栈 AcWing 3302. 表达式求值
Configuration method and configuration file of SolidWorks GB profile library
Application of recyclerview
4.Oracle-重做日志文件管理
[QT] QT multithreading development qthread
MPLS experiment
Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations
Utf8 encoding
How to understand the definition of sequence limit?
Vscode configures the typera editor for MD
Filter the numbers and pick out even numbers from several numbers
Adg5412fbruz-rl7 applies dual power analog switch and multiplexer IC
博弈论 AcWing 891. Nim游戏
LeetCode-61
Find the combination number acwing 887 Find combination number III
Presentation of attribute value of an item
PR automatically moves forward after deleting clips
Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter