2018-04-25T10:32:35-04:00
Write a function remove_odd that takes in a set of integers and removes all the odd elements.
Hint: you will need to use an iterator to iterate through the elements in a set.
Hint: In C++11, an auto keyword can be use to automatically infer the type. e.g. autoiter = s.begin()
#include <set>
using namespace std;
void remove_odd(set<int> s) {
//code
}
1
2018-04-26T07:47:07-0400
void remove_odd(std::set<int> &s) { for (auto _it = s.begin(); _it != s.end(); ) { if (*_it % 2 != 0) s.erase(_it++); else { ++_it; }; } };
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS !
Learn more about our help with Assignments:
C++
Comments