思路:
方法1:
 利用栈的先进后出特性,从头遍历链表,开始入栈
 到末尾后,开始出栈并放入vector中
class Solution {
public:
    vector<int> reversePrint(ListNode* head) {
        stack<int> temp;
        while(head!=NULL){
            temp.push(head->val);
            head=head->next;
        }
        vector<int> ans;
        while(!temp.empty()){
            ans.push_back(temp.top());
            temp.pop();
        }
        return ans;
    }
};
 
方法二:从头遍历,直接按顺序放入vector,再使用reverse(res.begin(),res.end());
 反转vector,就能达到从尾到头的链表输出
class Solution {
public:
    vector<int> reversePrint(ListNode* head) {
        vector<int> ans;
        while(head!=NULL){
            ans.push_back(head->val);
            head=head->next;
        }
        reverse(ans.begin(),ans.end());
        return ans;
    }
};
 










