/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
stack<int> s;
vector<int> result;
ListNode* p = head;
while(p != NULL){
s.push(p->val);
p = p->next;
}
while( !s.empty()){
result.push_back(s.top());
s.pop();
}
return result;
}
};