编写一个程序,实现输出链表中倒数第K个结点
ListNode * FindKthToTail(LisNode *head, unsigned int k)
{
if(head == NULL || K == 0) //入口参数检查!!!
{
return NULL;
}
int i;
ListNode *pAhead = head;
ListNode *pBehind = NULL;
for(i = 0; i < k - 1; ++i)
{
if(pAhead->next != NULL)
{
pAhead = pAhead->next;
}
else
{
return NULL;
}
}
pBehind = head;
while(pAhead->next != NULL)
{
pAhead = pAhead->next;
pBehind = pBehind->next;
}
Return pBehind;
}