Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
unique_list
#include <iostream> #include <cmath> #include <list> // removes the second element if consecutive element difference is less than 2 bool differenceOfTwo(int first, int second) { return (std::fabs(first - second) < 2); } int main() { std::list<int> duplicates {0,1,1,2,3,4,4,5,5,5,5,7,8,8,9}; // Unique function removes the consecutive duplicate elements in a list duplicates.unique(); // Printing the unique elements std::cout << "Unique Elements are : " ; for(auto element: duplicates) { std::cout << element << " "; } // Computing and Printing the elements which differ by 2 or more std::cout << "\n"; std::cout << "Printing elements which differ by 2 or more : "; duplicates.unique(differenceOfTwo); for(auto element: duplicates) { std::cout << element << " "; } return 0; }
run
|
edit
|
history
|
help
0
Rubix
copy_if c++98
TempQuickDoubly
pattern
A number is prime or not
Merge intervals leetcode
ONP
BinomialPoisson
Dar
cynb