Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » C++ STL

List functions in C++ STL (Standard Template Library)



C++ STL - List functions: Here, we are going to learn about the list functions in C++ Standard Template Library (C++ STL).
Submitted by IncludeHelp, on November 01, 2018

Following are the C++ STL list functions (public member functions) that can be used for various list operations, the functions are

Function Description Syntax (consider 'list' is the name of any integer list)
empty() Checks whether given list is empty or not. It returns 1 (true) if list is empty else it returns 0 (false). list.empty();
size() Returns size of the list list.size();
sort() Sorts the list in ascending order list.sort();
reverse() Reverses the list (elements of the list) list.reverse();
remove() Removes all occurrences of given elements from the list. list.remove(element);
remove_if() Remove set of the elements based on the test condition (if test condition is true for the element, element will be removed and it is applicable on all the occurrences of the element which satisfy the test condition). list.remove_if(test_condition);
front() Returns the first element of the list list.front();
back() Returns the last element of the list list.back();
push_front() Inserts the element at the front (beginning) to the list list.push_front(element);
push_back() Insert the element at the back (end) to the list list.push_back(element);
pop_front() Removes the element from the front (beginning) of the list list.pop_front();
pop_back() Removes the element from the back (end) of the list list.pop_back();
insert() Inserts the element at specified index/position list.insert(element,index);
begin() and end() Return the iterator pointing first and last element of the list list.begin(); and list.end();
rbegin() and rend() Return the iterator pointing first and last element of the list (in reverse order) i.e. first element will be considered as last and last will be consider as first list.rbegin(); and list.rend();
assign() Assigns the new set of elements or replaces the current with the new set of elements list.assign(n, element)
//will assign ‘element’, ‘n’ times to the list
merge() It merges two lists. list1.merge(list2);
unique() It removes consecutive elements from the list. list.unique();
erase() Removes an element or set (i.e. a range) of the elements from the list

Ref: List in C++ STL






Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates



© https://www.includehelp.com (2015-2018), Some rights reserved.