JZ6 从尾到头打印链表
/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : * val(x), next(NULL) { * } * }; */ class Solution { public: stack <int> a; vector<int> printListFromTailToHead(ListNode* head) { vector<int> vec; ListNode* current_p = head; if(head!=NULL){ while(current_p -> next != NULL){ a.push(current_p -> val); current_p = current_p -> next; } a.push(current_p -> val); int temp; while(!a.empty()){ temp = a.top(); a.pop(); vec.push_back(temp); } } return vec; } };