Summary of map/multimap in STL

Source: Internet
Author: User

(1) Before using map/multimap, the header file <map >:# include <map> must be included and be the same as all associated containers, map/multimap is usually completed by balancing Binary Trees (2) namespace std {template <class key, class T, class Compare = less <key>, class Allocator = allocator <pair <const key, T> class map; template <class key, class T, class Compare = less <key>, class Allocator = allocator <pair <const key, T> class multimap;} The first template parameter is treated as the key of the element, and the second is treated as the value of the element. The key/value must be assignable and copyable. for sorting, The key must be comparable. The third parameter is the sorting criterion. Like map/multimap, This sorting criterion must be strict weak ordering. The order of elements is determined by their keys and has nothing to do with value, map/multimap Automatically sorts elements based on their keys. (3) map/multimap operation function: map c generates an empty map/multimapmap c (op) using op as the sorting criterion to generate an empty map/multimapmap c1 (c2) generate a copy of a map/multimap map c (beg, end) to generate a map/multimapmap c (beg, end, op) with elements in the interval [beg, end) uses op as the sorting criterion and generates a map/multimapc by using the elements in the interval [beg, end. ~ Map () destroys all elements and releases the memory. map can be in the following forms: map <Key, Elem>, map <Key, Elem, op>, multimap <Key, elem>, multimap <Key, Elem, op> c. size () returns the current number of elements c. empty () determines whether c is null. max_size () returns the maximum allowed element value c1 compare c2 compare = ,! =, <,>, <= And> = c. count (elem) returns the number of elements whose "key value is equal to key" c. find (elem) returns the iterator for the first element of "key value equals key". If it cannot be found, end () c. lower_bound (key) returns the first pluggable position of the element whose key value is key, that is, the first element position c of the key value> = key. upper_bound (key) returns the last pluggable position of the element whose key value is key, that is, the first element position c of the key value> key. when _range (key) returns the first and last pluggable positions of the elements whose key value is key, that is, the element range lower_bound () of "key value = key () the upper_bound () and upper_range () actions are very similar to the set function. The only difference is that the element is a key/value pair. C1 = c2 assign all c2 elements to c1c1. swap (c2) SWAps c1 and c2 elements. begin () returns a bidirectional access iterator (the key is regarded as a constant) pointing to the first element c. end () returns a bidirectional access iterator (the key is regarded as a constant) pointing to the next position of the last element c. rbegin () returns a reverse iterator pointing to the first element c. rend () returns a reverse iterator pointing to the next position of the last element of the reverse iteration. The element here is a key/value pair (pair <const key, T> ). C. insert (elem) inserts an elem copy and returns the location of the new element c. insert (it, elem) an insert elem copy returns the location of the new element (it is a search start point that indicates the insert operation) c. insert (beg, end) inserts all element copies in the [beg, end) interval, no return value c. erase (elem) removes all elements whose values are equal to elem and returns the number of removed elements. erase (it) removes the elements at the it location and does not return c. erase (beg, end) removes all elements in the [beg, end) range, and no c. clear () clears the container. The element here is a key/value pair (pair <const key, T> ).

  

Related Article

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.