We have discussed List and some of its functions in the following article:
Some more useful functions are discussed in this article
1. emplace(position, value) :- This function is used to insert an element at the position specified.
2. emplace_back(value) :- This function adds value at end of list. It is different from push_back() by the fact that it directly creates element at position whereas push_back() first makes a temporary copy and copies from there. emplace_back() is faster in implementation than push_back() in most situations.
3. emplace_front :- This function adds value at beginning of list. It is different from push_front() by the fact that it directly creates element at position whereas push_front() first makes a temporary copy and copies from there. emplace_front() is faster in implementation than push_front() in most situations.
List after emplace_back operation is : 1 2 3 4 5 List after emplace_front operation is : 50 40 30 20 10 1 2 3 4 5 List after emplace operation is : 50 100 40 30 20 10 1 2 3 4 5
4. merge(list2) :- This function is used to merge list2 with list1. If both the lists are in sorted order, then the resulting list is also sorted.
5. remove_if(condition) :- This function removes the element from list on the basis of condition given in its argument.
list1 after merge operation is : 1 2 2 3 4 6 list1 after remove_if operation is : 2 2 4 6
6. unique() :- This function is used to delete the repeated occurrences of the number. List has to be sorted for this function to get executed.
7. splice(position, list2) :- This function is used to transfer elements from one list into another.
list1 before unique operation is : 1 1 1 2 2 3 3 4 list1 after unique operation is : 1 2 3 4 list1 after splice operation is : 1 2 4 6 2 3 4
8. swap(list2) :- This function is used to swap one list element with other.
The contents of 1st list before swapping are : 1 2 3 4 The contents of 2nd list before swapping are : 2 4 6 The contents of 1st list after swapping are : 2 4 6 The contents of 2nd list after swapping are : 1 2 3 4
This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Some useful C++ tricks for beginners in Competitive Programming
- Some interesting facts about static member functions in C++
- Which C++ libraries are useful for competitive programming?
- Forward List in C++ | Set 1 (Introduction and Important Functions)
- Forward List in C++ | Set 2 (Manipulating Functions)
- C/C++ Ternary Operator - Some Interesting Observations
- Some Interesting facts about default arguments in C++
- Publicly inherit a base class but making some of public method as private
- Virtual Functions and Runtime Polymorphism in C++ | Set 1 (Introduction)
- Can static functions be virtual in C++?
- Virtual functions in derived classes
- Functions that cannot be overloaded in C++
- Pure Functions
- Can virtual functions be private in C++?
- Can virtual functions be inlined?
- Macros vs Functions
- fill() and fill_n() functions in C++ STL
- Return from void functions in C++
- isalpha() and isdigit() functions in C with cstring examples.
- strtok() and strtok_r() functions in C with examples