Exercise 10.26
Back_inserter creates an iterator that uses push_back.
Front_inserter creates an Push_front iterator.
Inserter Create an iterator that uses insert. This function receives the second argument, which must be an iterator to the given container. The element will be inserted before the element represented by the given iterator.
Exercise 10.27
1#include <iostream>2#include <string>3#include <iostream>4#include <string>5#include <vector>6#include <algorithm>7#include <list>8#include <functional>9#include <iterator>Ten using namespacestd; One using namespaceplaceholders; A - voidElmdups (vector<string> &vec, list<string> &); - the intMain () - { -vector<string> words{" the","Quick","Red","Fox","jumps"," Over"," the","Slow","Red","Turtle" }; -list<string>Li; + elmdups (words, Li); - for(auto C:li) +cout << C <<Endl; ASystem"Pause"); at return 0; - } - - voidElmdups (vector<string>& Vec, list<string> &Li) - { - sort (Vec.begin (), Vec.end ()); in unique_copy (Vec.begin (), Vec.end (), Back_inserter (LI)); -}
Exercise 10.28
1#include <iostream>2#include <vector>3#include <list>4#include <algorithm>5 6 using namespacestd;7 8 intMain ()9 {Tenvector<int>Vec; Onelist<int> vec2 = {Ten, One, A},VEC3 = {Ten, One, A},VEC4 = {Ten, One, A}; A for(inti =1; I <=9; ++i) - Vec.push_back (i); - the copy (Vec.cbegin (), Vec.cend (), Front_inserter (VEC2)); - for(Auto it = Vec2.begin (); It! = Vec2.end (); + +it) -cout << *it <<" "; -cout <<Endl; + - copy (Vec.cbegin (), Vec.cend (), Back_inserter (VEC3)); + for(Auto it = Vec3.begin (); It! = Vec3.end (); + +it) Acout << *it <<" "; atcout <<Endl; - - copy (Vec.cbegin (), Vec.cend (), Inserter (Vec4,vec4.begin ())); - for(Auto it = Vec4.begin (); It! = Vec4.end (); + +it) -cout << *it <<" "; -cout <<Endl; in return 0; -}
C++primer 10.4.1 sessions