思想:设两个指针p,q,指向头节点,p开始遍历,当p到达k节点时,q从头结点开始遍历,当p遍历到表尾时,q所指向的节点即为倒数第K个节点
q = p = L->next; int count = 0;
while(p != NULL){if (count < k) count ++; else q = q->next; p = p->next}
if (count < k) return 0; else prinf("%d", q->data);
思想:设两个指针p,q,指向头节点,p开始遍历,当p到达k节点时,q从头结点开始遍历,当p遍历到表尾时,q所指向的节点即为倒数第K个节点
q = p = L->next; int count = 0;
while(p != NULL){if (count < k) count ++; else q = q->next; p = p->next}
if (count < k) return 0; else prinf("%d", q->data);