C++ code to demonstrate forward list part - 2

Suman Barik
0
// C++ code to demonstrate working of
// push_front(), emplace_front() and pop_front()
#include <forward_list>
#include <iostream>
using namespace std;

// Driver Code
int main()
{
// Initializing forward list
forward_list<int> flist = { 10, 20, 30, 40, 50 };

// Inserting value using push_front()
// Inserts 60 at front
flist.push_front(60);

// Displaying the forward list
cout
<< "The forward list after push_front operation : ";
for (int& c : flist)
cout << c << " ";
cout << endl;

// Inserting value using emplace_front()
// Inserts 70 at front
flist.emplace_front(70);

// Displaying the forward list
cout << "The forward list after emplace_front "
"operation : ";
for (int& c : flist)
cout << c << " ";
cout << endl;

// Deleting first value using pop_front()
// Pops 70
flist.pop_front();

// Displaying the forward list
cout << "The forward list after pop_front operation : ";
for (int& c : flist)
cout << c << " ";
cout << endl;

return 0;
}

Tags

Post a Comment

0Comments
Post a Comment (0)