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;
    }

    天天向上
  • 相关阅读:
    Jmeter+ant+jenkin接口自动化发邮件
    BadBoy 参数化录制,并导入JMeter
    Jmeter 移动端录制
    Pytest 操作
    Pytest框架简介与安装
    Fiddler iOS抓包
    Fiddler Android APP 抓包
    random的使用
    scanner的使用与匿名对象的使用
    标准的类,API的初步使用
  • 原文地址:https://www.cnblogs.com/hg07/p/12728051.html
Copyright © 2011-2022 走看看