剑指offer-倒序打印链表
2017-04-03 14:24
399 查看
重点提示
面试过程中若需要修改输入的数据,可以提前问面试官是否允许做修改;
需要考虑程序的鲁棒性(其实就是容不容易崩);
当遇到逆序情况时,要联想到栈的性质,先进后出,后进先出;
用reverse函数;
面试过程中若需要修改输入的数据,可以提前问面试官是否允许做修改;
需要考虑程序的鲁棒性(其实就是容不容易崩);
当遇到逆序情况时,要联想到栈的性质,先进后出,后进先出;
typedef struct linkList { int data; struct linkList *next; }ListNode; void ReversinglyPrint(ListNode *phead) { std::stack<ListNode *> nodes; ListNode *p = phead; while (p!= NULL) { nodes.push(p); p = p->next; } while (!nodes.empty()) { p = nodes.pop(); printf("%d ", p->data); nodes.pop(); } }
用reverse函数;
class Solution { public: vector<int> printListFromTailToHead(ListNode* head) { vector<int>res; while(head!=NULL) { res.push_back(head->val); head=head->next; } reverse(res.begin(),res.end()); return res; } };
相关文章推荐
- 剑指offer之倒序打印链表
- 剑指offer--从尾到头打印链表
- 剑指offer--(3) 从尾到头打印链表
- 剑指Offer_6_从尾到头打印链表
- 【剑指Offer】面试题5:从尾到头打印链表
- 【剑指offer】从尾到头打印链表
- 【剑指Offer面试编程题】题目1511:从尾到头打印链表--九度OJ
- 剑指offer-从尾到头打印链表
- 剑指offer第三题打印链表
- 剑指offer之从尾到头打印链表
- 剑指Offer:从尾到头打印链表
- java 剑指offer 第三题:输入一个链表,从尾到头打印链表每个节点的值。
- 剑指offer之从尾到头打印链表
- 剑指offer之从尾到头打印链表(Python)
- 剑指offer-Java-从尾到头打印链表
- 剑指offer:面试4从尾到头打印链表
- 剑指offer第三题【从尾到头打印链表】c++实现
- 剑指offer-2、从尾到头打印链表
- 剑指offer_面试题5_从尾到头打印链表(栈和递归实现)
- 剑指offer:从尾到头打印链表