题解 | #输出单向链表中倒数第k个结点#
输出单向链表中倒数第k个结点
https://www.nowcoder.com/practice/54404a78aec1435a81150f15f899417d
#include <stdio.h> typedef struct ListNode { int m_nKey; struct ListNode* m_pNext; }LISTNODE; int main() { LISTNODE liBuf[1008] = {0}; int index = 0; LISTNODE* head; LISTNODE* tail; int listLen; int val = 0; int k = 0; LISTNODE *p=NULL; while(EOF != scanf("%d",&listLen)) { head = liBuf+(index++); tail = head; val = 0; for(int i = 0; i < listLen; i++) { scanf("%d",&val); tail->m_nKey = val; tail->m_pNext = liBuf+(index++); tail = tail->m_pNext; tail->m_pNext = NULL; } k = 0; scanf("%d",&k); p = head; for(int i = 0; i < listLen - k; i++) p = p->m_pNext; printf("%d\n",p->m_nKey); } return 0; }