logo CodeStepByStep logo

collectionMystery4

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 collectionMystery4(vector<int>& v) {
    for (int i = 1; i < v.size(); i += 2) {
        if (v[i - 1] >= v[i]) {
            v.erase(v.begin() + i);
            v.insert(v.begin() + 0, 0);
        }
    }
    cout << v << endl;
}
{10, 20, 10, 5}
{8, 2, 9, 7, -1, 55}
{0, 16, 9, 1, 64, 25, 25, 14, 0}

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.