#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void myfunction(int i)
{
cout<<" "<<i;
};
void multiply(int a)
{
a*2;
}
int main()
{
int t[]={10,5,9,6,2,4,7,8,3,1};
vector<int> v1(t,t+10);
for_each(v1.begin(),v1.end(),multiply);
iter_swap(v1.begin(), t+9);
for_each(v1.begin(),v1.end(),myfunction);
return 0;
}
Hello, I actually have question about this code.
when I run this, I see the result is 1 5 9 6 2 4 7 8 3 1 and I am not sure why the last element is still 1 even though I assigned the statement iter_swap(v1.begin(), t+9); in the middle.
I am the kind of beginner so I appreciate someone answer this question.
Thank you.