首页 > 其他 > 详细

从尾到头打印链表

时间:2015-05-07 22:04:05      阅读:227      评论:0      收藏:0      [点我收藏+]

题目描述

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

/**
*  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)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!