* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode next;
* ListNode(int x) : val(x), next(NULL) {}
* };
/
class Solution {
public:
vector< int > printListReversingly(ListNode* head) {
vector< int > out;//做麻烦了,根本不需要栈
stack< int > s;
while(head)
{
s.push(head->val);
head=head->next;
}
while(!s.empty())
{
int x=s.top();
s.pop();
out.push_back(x);
}
return out;
}
};