[原创]单链表逆序

duweifu posted @ 2011年9月07日 23:03 in Scrawl with tags 单链表 逆序 , 726 阅读
LinkNode* ReverseLink(LinkNode *pLink)
{
	if (pLink->pNext == NULL || pLink == NULL)
		return pLink;
	LinkNode *pHead = ReverseLink(pLink->pNext);
	pLink->pNext->pNext = pLink;
	pLink->pNext = NULL;
	return pHead;

}

 

LinkNode* ReverseLink(LinkNode *pLink)
{
	if (pLink->pNext == NULL || pLink == NULL)
		return pLink;
	LinkNode *p, *q, *r;
	p = NULL;
	q = pLink;
	r = q->pNext;
	while (r != NULL)
	{
		q->pNext = p;		
		p = q;
		q = r;
		r = r->pNext;

	}
	q->pNext = p;
	return q;
}

 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter