9th Chapter Sequential Container
9.1 Sequential Container Overview
- Basic principles for selecting containers:
- Vectors should be used unless there are good reasons to choose other containers;
- If the program has many small elements and the extra overhead of space is important, do not use list or forward_list;
- If the program requires random access to elements, the vector or deque should be used;
- If the program requires inserting or deleting elements in the middle of the container, use list or forward_list;
- Use Deque if the program needs to insert or delete elements at the beginning and tail, but not insert or delete in the middle;
- If the program needs to insert elements in the middle of the container only when the input is read, then random access to the elements is required:
A) First, determine if you really need to add elements in the middle of the container. When working with input data, it is often easy to append data to the vector and then reorder it by invoking the sort function of the standard library to avoid adding elements in an intermediate position.
b) If the element must be inserted in an intermediate position, consider using list in the input phase, and once the input is complete, copy the contents of the list into a vector.
9.2 Container Library Overview
9.2.4 Container definition and initialization
9.2.5 Assignment and Swap
- Swap does not copy, delete, or insert any elements except array, so it is guaranteed to complete in constant time;
9.3 Sequential Container Operations
9.3.1 adding elements to a sequential container
9.3.2 accessing elements
9.3.3 deleting elements
9.3.4 Special Forward_list operation
9.3.5 Changing the container size
9.5.1 other ways to construct string
9.5.2 other ways to change string
9.5.3 String Search operation
9.5.4 Compare function
9.5.5 Numeric conversions
9.6 Container Adapter
Stack Adapter
Queue Adapter
C++primer 5th Edition Reading notes (Chapter 9th)