Question: C++ What am I missing here? #include #include using namespace std; void reverse(vector &a) { // a = { 1,2,3,4,5 }; cout < < The

C++ What am I missing here?

#include #include using namespace std;

void reverse(vector&a) { // a = { 1,2,3,4,5 };

cout << "The normal vector: "; for (unsigned i = 0; i <= 4; i++) { cout << a.at(i) << " "; } cout << endl;

cout << "The reversed vector: "; for (unsigned i = 0; i <= a.size()/2; i++) { int temp = a.at(i); a.at(i) = a.at(a.size() - 1 - i); a.at(a.size() - 1 - i) = temp; cout << a.at(i) << " "; } cout << endl; } int main() { vector a; a = { 1,2,3,4,5 }; reverse(a); system("pause"); return 0; }

//When I try to reverse the vector, I get 5 4 3, how do I get 2 1?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!