从尾到头打印链表

时间:2015-05-07 22:04:05   收藏:0   阅读:227

题目描述

输入一个链表,从尾到头打印链表每个节点的值。返回新链表的头结点。

/**
*  struct ListNode {
*       int val;
*       struct ListNode *next;
*       ListNode(int x) :
*             val(x), next(NULL) {
*       }
*  };
*/
 
class Solution {
public:
  vector<int> printListFromTailToHead(struct ListNode* head) {
    vector<int> a;
        if(head!=NULL)
        {
            if(head->next!=NULL)
            {
                a=printListFromTailToHead(head->next);
            }
            a.push_back(head->val);
        }
        return a;
  }
};

原文:http://blog.csdn.net/a819721810/article/details/45566917

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!