list::unique() is an inbuilt function in C++ STL which removes all duplicate consecutive elements from the list. It works only on sorted list.
Parameters: The function accepts a single and optional parameter which is a binary predicate that returns true if the elements should be treated as equal. It has following syntax:
bool name(data_type a, data_type b);
Return value: This function does not return anything.
Below is the implementation of above function:
List is: 2.55 3.15 4.16 4.77 12.65 13.59 List is: 2.55 3.15 4.16 12.65 13.59
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- forward_list::unique() in C++ STL
- Count number of unique Triangles using STL | Set 1 (Using set)
- list::push_front() and list::push_back() in C++ STL
- list::pop_front() and list::pop_back() in C++ STL
- list::front() and list::back() in C++ STL
- list::empty() and list::size() in C++ STL
- list::remove() and list::remove_if() in C++ STL
- list::emplace_front() and list::emplace_back() in C++ STL
- list::begin() and list::end() in C++ STL
- How to insert elements in C++ STL List ?
- Delete elements in C++ STL list
- List in C++ Standard Template Library (STL)
- list::clear() in C++ STL
- list::swap() in C++ STL
- list::operator= in C++ STL
- std::list::sort in C++ STL
- list cbegin() and cend() function in C++ STL
- list assign() function in C++ STL
- list push_back() function in C++ STL
- list back() function in C++ STL
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : syvs