#include<stdio.h>
typedef struct node{
int data;
struct node *next;
}*LinkList; //
int main(){//用头插法
int n,s,count=0;
scanf("%d",&n);//储存k
scanf("%d",&s);//储存第一个数字
LinkList head=(LinkList)malloc(sizeof(struct node));//头结点
head->next=NULL;//
while(s>=0){
count++;//计数
LinkList p=(LinkList)malloc(sizeof(struct node));//创造节点时通常会动态分配空间避免空间被覆盖//每次都创造p来存储新数据
p->data=s;//第一个数字赋值给p
//头插法插入节点
p->next=head->next;
head->next=p;
注:这里顺序不能变,不然head->next就不代表原来的next了
scanf("%d",&s);
}
//负数刚好不会储存进来
if(n>count || n<=0){//错误的位置
printf("NULL\n");
return 0;
}
//由图示可知头节点为空
LinkList q=head->next;//创造空结点指向第一个节点开始遍历
for(int i=1;i<n;i++){//找到指定位置,移动n-1次
q=q->next;
}
printf("%d",q->data);
return 0;
}