C + + version fifth exercise 9.26

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.