This is my first ever post on this site as a C++ beginner. My question is rather simple. Write a function that reverse the order of elements in a vector. For example, 1, 3, 5, 7, 9 becomes 9, 7, 5, 3, I. The reverse function should produce a new vector with the reversed sequence, leaving its original vector unchanged.
And here is my code. When I run it there is nothing coming after the word "Printing". I am pretty sure I made a silly and simple mistake somewhere but just couldn't figure it out. Would appreciate any help.Cheers.
void reverse_a(const vector<int>&v1, vector<int>&v2)
{
//this function creates vector2 with the reverse sequence of elements from vector 1
for(int i=v1.size()-1;i<=0;--i)
{
v2.push_back(v1[i]);
}
}
void print(const vector<int>&v)
{
cout<<"Printing"<<endl;
for(int i=0;i<v.size();++i)
cout<<v[i]<<",";
cout<<"\n"<<"end of print.\n";
}
int main()
{
vector<int>v1;
vector<int>v2;
int input;
while(cin>>input)
v1.push_back(input);
reverse_a(v1,v2);
print(v2);
keep_window_open("`");
}