Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

l Summarize the process of evaluating HR performance.

Answered: 1 week ago