list::push_back() method

Lists are sequence containers available in the C++ Standard Library. They allow non-contiguous memory allocation. List containers are implemented as doubly-linked lists. Compared to other sequence containers (eg: arrays, vectors etc.), lists have a better performance when it comes to inserting, moving or deleting elements. The list::push_back() is a method available in the STL which adds a new element at the end of the list container, after its current last element. It effectively increases the container size by one.



Parameters: The list::push_back() method accepts a single parameter:
•Element to be inserted to the list
Return value: none

Example of list::push_back() method

#include <iostream>
#include <list>

using namespace std;

int main()
    list<int> L;

    cout<<"List contains:  \n";

    for( list<int>::iterator it = L.begin(); it != L.end(); ++it)
        cout<<*it<<" <--> ";


List contains:
3 <--> 4 <--> 5 <--> 6 <--> NULL

This article is written by

Please comment below, if you have any doubts or find any error in the above article.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
[gravityforms id="5" description="false" titla="false" ajax="true"]