/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
#include <cstddef>
class Solution {
public:
ListNode* reverseList(ListNode* cur,vector<int>& a)
{
if (cur->next==nullptr)
{
return cur;
}
else
{
ListNode* next=reverseList(cur->next,a);
a.push_back(next->val);
next->next=cur;
return cur;
}
}
vector<int> printListFromTailToHead(ListNode* head) {
ListNode* next=nullptr;
ListNode* front=nullptr;
vector<int> a;
if (!head)
{
return a;
}
head=reverseList(head,a);
a.push_back(head->val);
// while(head)
// {
// next=head->next;
// head->next=front;
// front=head;
// head=next;
// }
// while(front)
// {
// a.push_back(front->val);
// front=front->next;
// }
return a;
}
};