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

    天天向上
  • 相关阅读:
    26个精选的JavaScript面试问题
    用js实现随机选取10–100之间的10个数字,存入一个数组,并排序
    小程序布局中class='container'的bug
    PHP接收数据数据包的几个方式
    LINUX命令
    VMware的下载安装
    php中Sessions
    php中Cookies
    php文件上传
    php文件处理
  • 原文地址:https://www.cnblogs.com/hg07/p/12728051.html
Copyright © 2011-2022 走看看