Source: http://blog.csdn.net/niushuai666/article/details/6654951
List
1. The List member function push_back () puts an object behind a list, while push_front () puts the object in front.
2. The list container does not support adding a number to the iterator to point to another object. That is to say, we cannot use milkshakes. Begin () + 2 to point to the third object in the list, because the STL list is implemented by a double-Chain List, which does not support random access. Vector and deque (vector and double-end Queue) and some other STL containers support Random Access
3. Using STL list and iterator, We need to initialize, compare, and incrementally traverse the container for iterator. The general STL for_each algorithm can alleviate our work. The for_each algorithm references the iterator range concept, which is a range specified by the starting iterator and the end iterator. The START iterator indicates where the operation starts, and the end iterator indicates where the operation ends, but it is not included in this range.
4. When the iterator range is used, this range indicates a list or a part of any other container for processing. Generally, the first iterator points to the starting position, and the second iterator points to the place where the processing is stopped. The elements specified by the secondary iterator are not processed.
5. In STL, sometimes containers support its own implementation of a special algorithm, which is usually used to improve performance. The list container has its own sort algorithm, because the general algorithm can only sort containers that provide random access to the elements in it, and because the list is implemented as a connected linked list, it does not support random access to its elements. Therefore, a special sort () member function is required to sort the list.
For various reasons, the container supports external functions (extra functions) when the performance needs to be high or there are special performance requirements, which can be achieved through the structural features of the constructor.
6. Be sure to separate the angle brackets or names with spaces to avoid confusion with the> shift operator. For example
Vector <list <int> veclis;
In this case, an error is reported, while in this case:
Vector <list <int> veclis;
You can avoid errors.
7. Vector-a standard and secure array in STL. You can only add data in front of the vector.
Deque (double-ended Queue) -- similar to vector in function, but data can be added to both ends.
List-the cursor can only move one step at a time. If you are familiar with the linked list, the list in STL is a two-way linked list (each node has two pointers pointing to the front and back ).
Set (SET) -- contains sorted data. The values of these data must be unique.
Map (ing)-A sorted set of binary groups. Each element in map is composed of two values. The key (key value, the key value in a map must be unique.) It is used for sorting or search. Its value can be retrieved again in the container. The other value is the value associated with the element. For example, in addition to finding a data in Ar [43] = "overripe", map can also find a data in Ar ["banana"] = "overripe. If you want to obtain the element information, you can simply enter the full name of the element.
Multiset (Multi-replica set) -- similar to set, however, the values do not need to be unique (that is, they can be repeated ).
Multimap (Multi- ing) -- similar to ing (MAP), however, key values do not need to be unique (that is, they can be repeated ).
8. The cursor is a pointer, but not just a pointer. A cursor is similar to a pointer, and its function is similar to a pointer. However, a cursor returns a value from the center of the container by reloading the "*" and "->" of a dollar.
9. iterator-for any container except the vector, you can use this cursor to take a step in the forward direction of the container in one operation. This means that you can only use the "++" Operator for such cursors. You cannot use the "--" or "+ =" operators. For the vector container, you can use any operator in "+ =", "-", "+ +", "-=", and "<", "<=", "> ", "> =", "=", "! = "And other comparison operators.
10. Besides the type and value, the template contains other parameters. You can pass a callback function (usually the Declaration "predicate" -- this is a function with a parameter that returns a Boolean value ). For example, if you want to automatically create a set and the elements in the set are arranged in ascending order, you can use a concise method to create a set class:
Set <int, greater <int> set1
Greater is another template function (fan-type function), which is used to sort these values after values are placed in the container. If you want to sort these values in descending order, you can write as follows:
Set <int, less <int> set1
11. The reserve in the vector is only used to pre-divide a piece of memory for the vector, mainly to improve efficiency: avoid re-allocation due to capacity changes during the continuous push_back process!
If no, after push_back, when the memory is insufficient, there will be memory reallocation and element copying. This is absolutely inefficient.
If the vector capacity is insufficient, it will
1. Allocate more space (generally increase n/2, and N is the original capacity)
2. copy the data in the existing vector to the new space one by one
3. Release all elements in the old space
4. vector points to the new space