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

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.