第9章 顺序容器
exercises section 9.2 9.2 list<deque<int> > list_deque_int; section 9.2.1 迭代器 1、迭代器与容器一样有公共的接口(forward_list的迭代器不支持递减运算符(--) exercise section 9.2.1 9.3、 1.迭代器必须指向同一个容器中的元素,或者容器最后一个元素之后的位置。 2.end不在begin之前。 9.4、 //p9_4.cpp #include <vector> #include <iostream> using namespace std; bool find(vector<int>::iterator first, vector<int>::iterator last, int val) { bool exist = false; //用来指示是否找到指定值,初始为false for(auto ix = first; ix != last; ++ix)//遍历迭代范围 { if(*ix == val) //若值相等 { exist = true; //说明找到了指定的值 break; //停止迭代 } } return exist; //返回exist,若存在则exist为true,否则为false } 9.5、 vector<int>::iterator find