单链表逆置

单链表的逆置问题,常常遇到,今天总结如下:

方法:头插法:

图示:


代码:

//翻转单链表
ListNode* Revers(ListNode* pHead)
{
	ListNode* newhead = NULL;
	ListNode* cur = pHead;
	while(cur)
	{
		
		ListNode* tmp= cur;
		cur = cur->next;
		tmp->next = newhead;
		newhead = tmp;
	}
	return newhead;
}

原文地址:https://www.cnblogs.com/melons/p/5791884.html