Exercise 9.26 uses the following code to define IA, copy ia to a vector and a list, use a single iterator version of erase to remove odd elements from the list, and remove even elements from the vector
1#include <iostream>2#include <list>3#include <vector>4 using namespacestd;5 6vector<int> Deletevect (vector<int> & Veca)//References7 {8Auto it =Veca.begin ();9 while(It! =veca.end ())Ten if(*it%2==0) Oneit = veca.erase (it);//Delete an even number of them A Else -++it; - returnVeca; the } - -list<int> DeleteList (list<int> & Veca)//References - { +Auto it =Veca.begin (); - while(It! =veca.end ()) + if(*it%2==1) Ait = veca.erase (it);//Delete the odd number of them at Else -++it; - returnVeca; - } - - intMain () in { - intIa[] = {0,1,1,2,3,5,8, -, +, -, the}; tovector<int>Vec; +list<int>lst; -Vec.assign (&ia[0],&ia[ One]);//Copy the ia[] into the vector container theLst.assign (&ia[0], &ia[ One]);//Copy the ia[] into the vector container * $cout <<"Please printf the odd number:"<<Endl;Panax Notoginseng Deletevect (VEC); - for(auto It:vec) the { +cout << It <<Endl; A } the +cout <<"Please printf the even number:"<<Endl; - deletelist (LST); $ for(auto It:lst) $ { -cout << It <<Endl; - } the GetChar (); - return 0;Wuyi}
C + + version fifth exercise 9.26