#include<bits/stdc++.h>
using namespace std;
typedef struct node {
int data;
node* next;
}node;
/*
void create(node*& l, int a[], int n) {
l = new node;
l->next = NULL;
node* p;
for (int i = 0; i < n; i++) {
p = new node;
p->data = a[i];
p->next = l->next;
l->next = p;
}
}*/
int main() {
/*int n;
cin >> n;
int* a;
a = (int*)malloc(n * sizeof(int));
for (i = 0; i < n; i++) {
cin >> a[i];
}*/
int k;
cin >> k;
node* l;
l = (node*)malloc(sizeof(node));
l->next = NULL;
node* p;
int a;
while(cin >> a&&a>=0){
p = (node*)malloc(sizeof(node));
p->data = a;
p->next = l->next;
l->next = p;
}
for (int i = 0; i < k; i++) {
l = l->next;
}
if (l) {
cout << l->data;
}
else cout << "NULL";
}
7-7 求链式线性表的倒数第K项(倒插法)
于 2024-03-16 19:26:33 首次发布