从尾到头打印链表
作者:互联网
struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } }; class Solution { public: vector<int> printListFromTailToHead(ListNode* head) { vector<int> vec; ListNode *p = head; vec = next(p, vec); return vec; } vector<int> next(ListNode *p, vector<int> vec){ if(p != NULL){ vec = next(p->next,vec); vec.push_back(p->val); } return vec; } };
标签:head,ListNode,val,到头,next,链表,vector,vec,从尾 来源: https://www.cnblogs.com/olajennings/p/12458503.html