链表的从尾到头打印(递归)

链表的从尾到头打印(递归)

递归打印链表

#include <bits/stdc++.h>
using namespace std;
 
void coutls(list<int>::iterator iter, list<int>::iterator node_end){
    if (iter!=node_end)
    {
        coutls(++iter, node_end);
        cout << *(--iter) << " ";
    }
}
 
int main( )
{
    list<int> node;
    
    for (int i = 1; i < 10; i++)
    {
        node.push_back(i);
    }
    auto it = node.begin();
    coutls(it, node.end());

    // it = node.begin();
    // while (it!=node.end())
    // {
    //     cout<< *it <<endl;
    //     it++;
    // }
    
    return 0;
}

相关推荐

  1. 到头打印

    2024-04-30 01:46:03       33 阅读
  2. 在解决问题中应用

    2024-04-30 01:46:03       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-30 01:46:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-30 01:46:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-30 01:46:03       87 阅读
  4. Python语言-面向对象

    2024-04-30 01:46:03       96 阅读

热门阅读

  1. Go Energy GUI框架 cli 使用

    2024-04-30 01:46:03       27 阅读
  2. 【迅投qmt系列】4、获取数据的方式

    2024-04-30 01:46:03       33 阅读
  3. docker数据卷

    2024-04-30 01:46:03       32 阅读
  4. 24年第一篇:个人小记

    2024-04-30 01:46:03       32 阅读
  5. 考研数学精选题目016

    2024-04-30 01:46:03       30 阅读
  6. 【题解】NowCoder 除2!

    2024-04-30 01:46:03       29 阅读
  7. 八大元素定位方法

    2024-04-30 01:46:03       33 阅读
  8. ASIM复现相关知识补充

    2024-04-30 01:46:03       32 阅读
  9. LeetCode 刷题 -- Day 6

    2024-04-30 01:46:03       34 阅读
  10. 保护您的连接:无线网络安全探究

    2024-04-30 01:46:03       36 阅读
  11. vue的build先上部署的 devServer不生效的场景记录

    2024-04-30 01:46:03       35 阅读