List Push Back Function

C++ List push_back

C++ List push_back inserts a new element at the end of the list and the size of the list container increases by one.

push_back function inserts element 5 at the end.

Syntax

Suppose a element is 'x':

Example

push_back(const value_type& x);

Parameter

x : It is the value to be inserted at the end.

Return value

It does not return any value.

Example 1

Let's see a simple example

Example

#include <iostream>
#include<list>
using namespace std;

int main()
{
   list<string> li={"C"," C++"," .Net"};
   list<string>::iterator itr;
   li.push_back(" java");
   li.push_back(" PHP");
  for(itr=li.begin();itr!=li.end();++itr)
   cout<<*itr;
    return 0;
}

Output:

Output

C  C++  .Net java PHP

In this example, push_back function inserts two strings i.e java and PHP at the end of the list.

Example 2

Let's see a simple example

Example

#include <iostream>
#include<list>
using namespace std;
int main()
{
   list<int> li={6,7,8,9};
   list<int>::iterator itr;
   li.push_back(10);
   li.push_back(11);
  for(itr=li.begin();itr!=li.end();++itr)
   cout<<*itr<<","
   return 0;
}

Output:

Output

6,7,8,9,10,11

Input Required

This code uses input(). Please provide values below: