logo CodeStepByStep logo

collectionMystery1

Language/Type: C++ collections vector STL

Write the output produced by the following function when passed each of the following vectors. Assume that a vector would print in the format {10, 20, 30}.

void collectionMystery1(vector<int>& list) {
    for (int i = 0; i < list.size(); i++) {
        int n = list[i];
        list.erase(list.begin() + i);
        if (n % 2 == 0) {
            list.push_back(i);
        }
    }
    cout << list << endl;
}
{5, 2, 5, 2}
{3, 5, 8, 9, 2}
{0, 1, 4, 3, 1, 3}

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.