Introduction to STL Containers

Source: Internet
Author: User

The STL container can be divided into the following categories: First: Sequence container, vector, list, deque,string. Two: Associative container, with set, Multiset, map, Mulmap, Hash_set, Hash_map, Hash_multiset, Hash_multimap III: Miscellaneous: Stack, queue, VA Larray, bitset the implementation of the various STL containers: (1) vector internal data structure: array. Random access to each element, the time required is constant. The time required to add or delete elements at the end is independent of the number of elements, and the time required to add or delete elements in the middle or at the beginning varies linearly with the number of elements. Elements can be dynamically added or reduced, memory management is done automatically, but programmers can use the reserve () member function to manage memory. The vector's iterator is invalidated when the memory is reassigned (the element it points to is no longer the same as before or after the operation). When putting more than capacity ()-when a size () element is inserted into a vector, memory is reassigned, all iterators are invalidated, otherwise an iterator to any element after the current element is invalidated. When an element is deleted, an iterator that points to any element after the deleted element is invalidated. (2) deque internal data structure: array. Random access to each element, the time required is constant. The time required to add elements at the beginning and end is independent of the number of elements, and the time required to add or delete elements in the middle varies linearly with the number of elements. Elements can be dynamically increased or decreased, memory management is done automatically, and no member functions are provided for memory management. Adding any element will invalidate the deque iterator. Deleting an element in the middle of a deque invalidates the iterator. When you delete an element at the head or tail of a deque, only the iterator that points to that element is invalidated. (3list internal data structure: Two-way loop linked list. An element cannot be accessed randomly. Bidirectional traversal is possible. The time required to add or remove elements at the beginning, end, and anywhere in the middle is constant. Elements can be dynamically added or reduced, and memory management is done automatically. Adding any element does not invalidate the iterator. When you delete an element, other iterators are not invalidated except for the iterator that points to the currently deleted element. (4) slist internal data structure: one-way linked list. Cannot traverse in two directions, only from front to back. Other features are similar to list. (5) stack adapter, which converts any type of sequence container to a stack, typically using deque as a supported sequence container. The element can only last in, first out (LIFO). You cannot traverse the entire stack. (6The queue adapter, which converts any type of sequence container into a queue, typically uses deque as a supported sequence container. The element can only be first in and out (FIFO). You cannot traverse the entire queue. (7The priority_queue adapter, which converts any type of sequence container into a priority queue, generally uses vectors as the underlying storage method. Only the first element can be accessed and the entire priority_queue cannot be traversed. The first element is always the highest-priority element. (8)Setkeys and values are equal. Key is unique. The elements are sorted in ascending order by default. If the element that the iterator points to is deleted, the iterator is invalidated. Any other operation that adds or removes an element does not invalidate the iterator. (9) The Multiset key can be not unique. Other features are the same as set. (TenHash_set compared to set, the elements in it are not necessarily ordered, but are assigned according to the hash function used, which provides a faster search speed (of course, it is related to the hash function). Other features are the same as set. ( One) The Hash_multiset key can be not unique. Other features are the same as hash_set. ( A) The map key is unique. The ascending order of the element default keys. If the element that the iterator points to is deleted, the iterator is invalidated. Any other operation that adds or removes an element does not invalidate the iterator. ( -) The Multimap key can be not unique. Other features are the same as map. ( -Hash_map compared to map, the elements in it are not necessarily ordered by key values, but are dispatched according to the hash function used, which provides a faster search speed (which is also related to the hash function). Other features are the same as map. ( the) The Hash_multimap key can be not unique. Other features are the same as hash_map.
Http://www.cnblogs.com/duzouzhe/archive/2010/01/12/1645191.html

Introduction to STL Containers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.