首页 > 其他 > 详细

剑指offer---反转链表

时间:2017-08-06 17:39:41      阅读:238      评论:0      收藏:0      [点我收藏+]
/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) :
            val(x), next(NULL) {
    }
};*/
class Solution {
public:
    ListNode* ReverseList(ListNode* pHead)
    {
        if(pHead==NULL)
        {
            return NULL;
        }
        
        ListNode* cur=NULL;
        ListNode* pre=NULL;
        ListNode* nex=NULL;
        
        cur=pHead;
        nex=cur->next;
        
        while(1)
        {
            
            if(nex==NULL)
            {
                break;
            }
            
            pre=cur;
            cur=nex;
            nex=nex->next;
            nex->next=cur;
        }
        
        return cur;
    }
};

 

剑指offer---反转链表

原文:http://www.cnblogs.com/159269lzm/p/7295204.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!