题样:

// import java.util.ArrayList;
// import java.util.Comparator;
// import java.util.Scanner;
// public class Main {
// public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
// int[] al = new int[1024];
// int n=sc.nextInt();
// int num=0;
// int a = sc.nextInt();
// for(int i=0;a!=-1;i++) {
// al[i]=a;
// a=sc.nextInt();
// num++;
// }
// if(n>0&&n<=num)System.out.println(al[num-n]);
// else System.out.println("NULL");
// }
// }
#include<stdio.h>
#include<stdlib.h>
struct node{
int date;
struct node* next;
};
int main(){
struct node* list = (struct node*) malloc (sizeof(struct node));
list->date = 0x7fffffff;
list->next = NULL;
long long k;
scanf("%lld",&k);
int date;
while(scanf("%d",&date)!=EOF&&date>=0){
struct node* newnode = (struct node*) malloc (sizeof(struct node));
newnode->date=date;
newnode->next=list->next;
list->next=newnode;
}
long long count = 1;
struct node* p=list->next;
while(p!=NULL){
if(count==k)break;
else {
count++;p=p->next;
}
}
if(p!=NULL)printf("%d",p->date);
else printf("NULL");
return 0;
}

链式线性表操作:找到倒数第K个元素
该博客探讨了如何在链式线性表中有效地找到倒数第K个元素的问题,适合数据结构学习者。通过实例和算法解析,阐述了解决这一问题的关键步骤和思路。
5806

被折叠的 条评论
为什么被折叠?



