从「林」开始--C++ primer 读书笔记 -- Part II: Containers and Algorithms
######################################################
// 声明 : 1 笔记基本都是从《C++ Primer第四版中英文对照.chm》复制而来!
2 延伸的知识会以黄色字体高亮,欢迎拍砖
3 个人阅读重点将用红色字体高亮!
######################################################
Chapter 9. Sequential Containers
1:The library defines three kinds of sequential containers: vector(Supports fast random access), list(Supports fast insertion/deletion), and deque (short for "double-ended queue" and pronounced "deck").
2: // copy elements from vec into ilist
list<int> ilist(vec.begin(), vec.end());
ilist.begin() + ilist.size()/2; // error: no addition on list iterators
The list iterator does not support the arithmetic operationsaddition or subtractionnor does it support the relational (<=, <, >=, >) operators. It does support pre- and postfix increment and decrement and the equality (inequality) operators.
3:
c.insert(p,t) |
list-----Inserts element with value t before the element referred to by iterator p. Returns an iterator referring to the element that was added. |
c.insert(p,n,t) |
list-----Inserts n elements with value t before the element referred to by iterator p. Returns void. |
c.insert(p,b,e) |
list-----Inserts elements in the range denoted by iterators b and e before the element referred to by iterator p. Returns void. |
c1.swap(c2) |
vector----Swaps contents: After the call c1 has elements that were in c2, and c2 has elements that were in c1. c1 and c2 must be the same type. Execution time usually much faster than copying elements from c2 to c1 |
c.pop_back() |
list-----Removes the last element in c. Returns void. Undefined if c is empty. |
c.pop_front() | Removes the first element in c. Returns void. Undefined if c is empty. |
来源:oschina
链接:https://my.oschina.net/u/152096/blog/53501