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

/**
*  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;

    }
};
原文地址:https://www.cnblogs.com/159269lzm/p/7260671.html