这里写图片描述

listNode *FindNtoTail(listNode *head,unsigned int n)
{
	if(head == NULL || n == 0) 
 		return NULL;
	
	listNode *pHead = head;
	listNode *pBehind = NULL;
	unsigned int i;
	// pHead 向前移动 n-1 
	for(i = 0;i<n-1;i++)
	{
		if(pHead->next != NULL)
			pHead = pHead->next;
		else
			return NULL;
	}
	pBehind = head;
	//同时移动,直到前一个指针到最后 
	while(pHead->next != NULL)
	{
		pHead = pHead->next;
		pBehind = pBehind->next;
	}
	return pBehind;
	
}

更多推荐