Created
October 21, 2018 06:13
-
-
Save ashiato45/258a73954f8e3d5c8b1b4cddc799153f to your computer and use it in GitHub Desktop.
Finding second maximum using std::set, for_each, custom ordering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto cmp = [](int a, int b){return a > b;}; | |
set<int, decltype(cmp)> s(cmp); | |
for_each(evens, evens + 100001, [&](int n){s.insert(n);}); | |
int num_secondpop_evens = 0; | |
if(s.size() > 1){ | |
num_secondpop_evens = *(++s.begin()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment