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