C++ STL中的RealSrar()和Read()函数

  1. 列表::rbegin() 是C++ STL中的内置函数,它返回指向列表最后元素的反向迭代器。

    语法:

    list_name.rbegin()

    参数: 此函数不接受任何参数。

    返回值: 它返回一个反向迭代器,该迭代器指向列表的最后一个元素。

    下面的程序说明了上述功能:

    // C++ program to illustrate the
    // list::rbegin() function
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    list< int > lis = { 10, 20, 30, 40, 50 };
    cout << "The list in reverse order: " ;
    for ( auto it = lis.rbegin(); it != lis.rend(); ++it)
    cout << *it << " " ;
    return 0;
    }

    
    

    输出:

    The list in reverse order: 50 40 30 20 10
    

  2. 列表::rend() 在C++ STL中是一个内置函数,它返回一个反向迭代器,指向列表开始之前的位置。

    语法:

    list_name.rend()

    参数: 该函数不接受任何参数。

    返回值: 它返回一个反向迭代器,该迭代器指向列表开头之前的位置。

    下面的程序说明了上述功能:

    // C++ program to illustrate the
    // list::rbegin() function
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    list< int > lis = { 10, 20, 30, 40, 50 };
    cout << "The list in reverse order: " ;
    for ( auto it = lis.rbegin(); it != lis.rend(); ++it)
    cout << *it << " " ;
    return 0;
    }

    
    

    输出:

    The list in reverse order: 50 40 30 20 10
    

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享