📌  相关文章
📜  C++ STL中的forward_list :: reverse()

📅  最后修改于: 2021-05-30 08:29:10             🧑  作者: Mango

std :: forward_list ::: reverse()是CPP STL中的内置函数,可反转forward_list中存在的元素的顺序。

句法:

forwardlist_name.reverse()

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

返回值:该函数没有返回值。它将反向转发列表。

下面的程序演示了以上函数:

程序1:

// C++ program to illustrate the
// reverse() function
#include 
using namespace std;
  
int main()
{
    // initialising forward list
    forward_list forward = { 10, 20, 40, 30, 70 };
  
    cout << "List elements before performing reverse operation: ";
  
    for (auto it = forward.begin(); it != forward.end(); ++it)
        cout << *it << " ";
  
    // Function that performs reverse operation
    forward.reverse();
  
    // printing elements of list
    cout << "\nList elements after performing reverse operation: ";
  
    for (auto it = forward.begin(); it != forward.end(); ++it)
        cout << *it << " ";
  
    return 0;
}
输出:
List elements before performing reverse operation: 10 20 40 30 70 
List elements after performing reverse operation: 70 30 40 20 10
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”