Jing's Interview Corner
Sunday, October 14, 2012
Reverse List
ListNode* ReverseList(ListNode *pHead)
{
if(NULL == pHead)
{
return NULL;
}
ListNode *cur = pHead;
ListNode *pre = NULL;
ListNode *next = NULL;
while(NULL != cur)
{
next = cur->next;
cur->next = pre;
pre = cur;
cur = next;
}
return pre;
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment