zoukankan      html  css  js  c++  java
  • 从尾到头打印链表

    #include "stdafx.h"
    #include <string>
    using namespace std;
    #include <vector>
    #include <stack>

    typedef struct tag_listnode
    {
        int data;
        struct  tag_listnode *next;

    }listnode;


    class Solution
    {
    public:
        Solution();
        ~Solution();

        vector<int> reseveListnode(listnode* head)
        {
            listnode *node = head;
            stack <int>  st;
            vector <int> vec;

            while (node !=nullptr)
            {
                st.push(node->data);
                node = node->next;
            }

            while (!st.empty())
            {
                vec.push_back(st.top());
                st.pop();
            }

            return vec;

        }

    private:

    };

    int main()
    {
        listnode head, node1, node2, node3, node4;
        node1.data = 11;  node1.next = &node2;
        node2.data = 22; node2.next = &node3;
        node3.data = 33; node3.next = &node4;
        node4.data = 44; node4.next = nullptr;
        head.next = &node1;
        Solution sou;
        vector <int>vecRet;
        vecRet = sou.reseveListnode(&head);
        return 1;
    }

    天天向上
  • 相关阅读:
    [20180814]校内模拟赛
    [20180812]四校联考
    [20180811]校内模拟赛
    [20180613]校内模拟赛
    网络流24题小结
    最小费用最大流——小结1
    ASP.NET MVC 下拉框的传值的两种方式
    面向方面编程(AOP)
    NPOI操作Excel
    IIS负载均衡
  • 原文地址:https://www.cnblogs.com/hg07/p/12728051.html
Copyright © 2011-2022 走看看