Testing coming up this thursday. need help! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Testing coming up this thursday. need help!

HeartyBowlHeartyBowl Posts: 2Member
Implement the function manipulateVector to generate the output shown below by using ONLY the functions listed in your reference list. This means that you cannot use any literals [color=Red](NO numbers)[/color] and [color=Red]you cannot use iterators.[/color]

For example, in the output below, the first line prints out the vector and the second line prints out a new vector from which the element at position 2 has been removed. You cannot use v.erase(2) ? you must use only the functions in the reference list and NO numbers.

Therefore, the correct implementation is:
v.erase(v.begin() + v.back());
where v.begin() will point to element 1 at index 0 and v.back()returns the last element, which is 2, making the iterator point to index 2.

1 4 9 8 6 5 7 3 2
1 4 8 6 5 7 3 2
1 8 6 5 7 3 2
1 8 1 6 5 7 3 2
1 8 1 1 6 5 7 3 2
1 2 8 1 1 6 5 7 3 2
2 3 7 5 6 1 1 8 2 1


By the way this exercise uses the stl.
i started by hardcoding the numbers into a vector.
So made a vector v. Then i inserted "1 4 9 8 6 5 7 3 2" by using the function v.push_back() for each number.
Now that i have a vector filled with the numbers above, I can't figure out how I'm supposed to print the items in the vector
without using an iterator! seems almost impossible
Sign In or Register to comment.