Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to remove all consecutive duplicate elements from std::forward_list in C++

1 Answer

0 votes
#include <iostream>
#include <forward_list>
 
int main()
{
    std::forward_list<int> fl = {1, 2, 2, 7, 7, 4, 1, 1, 8, 8, 8, 9};
 
    std::cout << "before:";
    for (auto val : fl)
        std::cout << ' ' << val;
    std::cout << '\n';
 
    fl.unique();
    std::cout << "after:";
    for (auto val : fl)
        std::cout << ' ' << val;
    std::cout << '\n';
}


 
/*
run:
   
before: 1 2 2 7 7 4 1 1 8 8 8 9
after: 1 2 7 4 1 8 9
  
*/


 



answered Dec 14, 2024 by avibootz

Related questions

1 answer 148 views
1 answer 152 views
1 answer 67 views
3 answers 139 views
3 answers 147 views
...