68 334
Assignments Done
Successfully Done
In November 2018

Answer to Question #76593 in C++ for LEE JIA WEI

Question #76593
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) {
Expert's answer
void remove_odd(set<int>& s)
auto it = s.begin();
while(it != s.end())
// erase if value is odd
if (*it % 2 == 0) it = s.erase(it);
// increment iterator if value is even
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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions