Modified algorithm
First, copy
Copy (Myvector.begin (), Myvector.end (), L1.begin ()), L1 must be capacity before copying, or the system will error
Copy_backward (Myvector.begin (), Myvector.end (), L1.end ()), and in L1 is copied from the back forward
Copy (Myvector.begin (), Myvector.end (),ostream_iterator<int> (cout, ",")), comma-delimited output
Second, transform ()
Simultaneous replication and transformation
Transform (V1.begin (), V1.end (), Back_inserter (L2), negate<int> ());//Multiply the number in V1 by-1, copy it into L2, and Back_inserter is the back iterator, You can copy without initializing capacity
cout << "List2" << Endl;
For_each (L2.begin (), L2.end (), print);
cout << Endl;
cout << "elements in L2 multiplied by ten" << Endl;
Transform (L2.begin (), L2.end (), L2.begin (), bind2nd (Multiplies<int> (), 10));
For_each (L2.begin (), L2.end (), print);
cout << Endl;
Transform (L2.begin (), L2.end (), ostream_iterator<int> (cout, ""), bind2nd (Divides<int> (), 2));// The elements in the L2 do not change, just the output
cout << Endl;
Transform (L2.begin (), L2.end (), L2.begin (), ostream_iterator<int> (cout, ","), multiplies<int> ());// The elements in the L2 and the elements in the L2 are multiplied separately by the output
Iii. Exchange
Swap (v1, v2);//Exchange V1,v2
Swap_ranges (V1.begin (), V1.begin () + 5, V2.begin ());//exchange of elements of a certain range
Iv. filling elements
Fill (V1.begin (), V1.begin () + 4, 9),//from v1[0] to V1[4] becomes 9
Fill_n (V1.begin (), 5,//v1[0] to v1[4] becomes 20
Generate (V2.begin (), V2.end (), Rand);//Generate random numbers
Generate (V2.begin (), 3,rand);//generate 3 random numbers
V. Replacement
Replace (V1.begin (), V1.end (), 7),//v1[6] becomes 99
Replace_if (V1.begin (), V1.end (), bind2nd (Less<int> (), 10), 11);//The judging condition is true replace
Vi. reversal
Reverse (V1.begin (), V1.end ());
Reverse_copy (V1.begin (), V1.end (),ostream_iterator<int> (cout, ",");//Reverse Output
Seven, rotation
Rotate (V1.begin (), V1.begin () +4,v1.end ());
Rotate_copy (V1.begin (), V1.begin () +3,v1.end (),ostream_iterator<int> (cout, ",");
STL Algorithm 2