首页 > 其他 > 详细

剑指offer---尾到头打印链表

时间:2017-07-30 23:00:42      阅读:166      评论:0      收藏:0      [点我收藏+]
/**
*  struct ListNode {
*        int val;
*        struct ListNode *next;
*        ListNode(int x) :
*              val(x), next(NULL) {
*        }
*  };
*/
class Solution {
public:
    vector<int> printListFromTailToHead(ListNode* head)
    {
        int jiediangeshu = 0;
        ListNode* cur = head;
        vector<int> re;
        while (cur != NULL)
        {
            ++jiediangeshu;
            cur = cur->next;
        }

        for (int i = (jiediangeshu - 1); i >= 0; --i)
        {
            ListNode* temp = head;
            int x=i;
            while (x>0)
            {
                temp = temp->next;
                --x;
            }

            re.push_back(temp->val);
        }

        return re;

    }
};

 

剑指offer---尾到头打印链表

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

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