剑指offer—从头到尾打印链表

来源:互联网 发布:linux查看php进程命令 编辑:程序博客网 时间:2024/05/17 21:44

华电北风吹
天津大学认知计算与应用重点实验室
日期:2015/9/30

题目描述
输入一个链表,从尾到头打印链表每个节点的值。

/***  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> lst;        ListNode *p = head;        while (p != NULL)        {            lst.insert(lst.begin(),p->val);            p = p->next;        }        return lst;    }};
0 0
原创粉丝点击