Associative container

map and set Is an association container , Not like vector,list,deque,forward_list It's a sequential container .

The bottom layer of sequential container is the data structure of linear sequence , It stores the element itself . Associative containers are also used to store data , It just stores <key,value> Key value pair of structure , More efficient in retrieval .

Key value pair

A structure used to represent one-to-one correspondence , This structure generally contains only two member variables key and value,key Represents the key value ,value Representation and key Corresponding information .

Tree structured associative container

STL A total of two managed containers with different structures are implemented : Tree structure and hash structure . There are four kinds of relational containers with tree structure :map,set,multimap,multiset.

set

1. The bottom layer is a binary search tree

2.set The key value pair of is actually <value,value>

3.set in value Is the only one

4. Modification is not allowed in the container , Because elements are always const constant , But it can be inserted or deleted

set Interface usage
std::set<int> first; // empty set of ints int myints[]= {10,20,30,40,50};
// Use array std::set<int> second (myints,myints+5); // range std::set<int> third
(second); // a copy of second std::set<int> fourth (second.begin(),
second.end()); // iterator ctor. std::set<int,classcomp> fifth; // class as
Compare

map

1. The bottom layer is usually a balanced binary search tree

2. support [] Subscript access

3. Store elements in a specific order
map() // Construct an empty map begin() and end() //begin: Position of the first element ,end Next position of the last element cbegin() and cend()
// And begin and end Same meaning , but cbegin and cend The element pointed to cannot be modified rbegin() and rend()
// reverse iterator ,rbegin stay end position ,rend stay begin position , his ++ and -- Operation and begin and end The operation moves in the opposite direction crbegin() and crend()
// And rbegin and rend Same location , Same operation , but crbegin and crend The element pointed to cannot be modified bool empty ( ) const
// testing map Is the element in empty , Is to return true, Otherwise return false size_type size() const // return map Number of valid elements in
mapped_type& operator[] (const key_type& k) // Go back key Corresponding value
pair<iterator,bool> insert (const value_type& x )
// stay map Insert key value pair in x, be careful x Is a key value pair , The return value is also a key value pair :iterator Represents the location of the newly inserted element ,bool Indicates that the release insertion is successful void erase (
iterator position ) // delete position Element at position size_type erase ( const key_type& x )
// Delete key value is x Element of void erase ( iterator first,iterator last ) // delete [first, last) Elements in interval
void swap (map<Key,T,Compare,Allocator>&mp ) // Swap two map Elements in void clear ( )
// take map Empty elements in iterator find ( const key_type& x)
// stay map Insert in key by x Element of , Find an iterator that returns the location of the element , Otherwise return end const_iterator find ( const key_type&
x ) const // stay map Insert in key by x Element of , Find the location that returns the element const iterator , Otherwise return cend size_type count (
const key_type& x ) const
// return key by x Key value in map Number of in , be careful map in key Is the only one , Therefore, the return value of this function is either 0, Or for 1, Therefore, this function can also be used to detect a key Is it map in

Technology
©2019-2020 Toolsou All rights reserved,
C++ of string of compare usage MySQL Basics Commonly used sentence ( Add / delete / modify query )C Language of a Gobang game implementation QT5.9 Use of learning notes QSqlQuery Method of Qt Getting Started tutorial 【 Basic controls 】QCalendarWidget calendar control java Polymorphic array of web Front end signature plug-in _signature_pad Plug in implements electronic signature function centos7 install RabbitMqspringboot use redis Experiment 4 Automated test tools - software test