9.1
(a):list,因为要频繁地进行任意位置的插入操作
(b):deque,因为只要在头尾位置进行插入/删除操作(相比于list,deque还支持快速随机访问)
(c):vector,没有要求进行插入/删除操作
9.2
list<deque<int>> l; //元素类型为另一种容器类型deque
9.3
两个迭代器begin和end构成一个迭代器范围。
两条限制:
- 它们指向同一个容器中的元素,或者是容器最后一个元素之后的位置;
- end可以与begin指向相同的位置,但不能指向begin之前的位置。
9.4
1 #include <iostream> 2 #include <vector> 3 #include <string> 4 #include <deque> 5 #include <list> 6 7 using namespace std; 8 9 bool is_find(vector<int>::iterator beg, vector<int>::iterator end, int x) 10 { 11 while (beg != end) { 12 if (*beg == x) 13 return true; 14 ++beg; 15 } 16 return false; 17 } 18 19 int main() 20 { 21 vector<int> vec{1, 2, 3, 4, 5}; 22 auto p1 = vec.begin(), p2 = vec.end(); 23 bool flag = is_find(p1, p2, 5); 24 if (flag) 25 cout << "Found!\n"; 26 else 27 cout << "Not Found!\n"; 28 return 0; 29 }