STL--<set>

1. The set will automatically sort the elements according to specific sorting criteria, the elements in the set are not allowed to be repeated, and the search operation efficiency will be very high O(log n)
2. Regarding set, it must be explained that set associative container. As a container, set is also used to store data types of the same data type and can be retrieved from a data set
Data, the value of each element in the set is unique , will not be added repeatedly, and the system can automatically sort according to the value of the element . It should be noted that the value of the number elements in the set cannot be changed directly. C++
The standard associative containers set, multiset, map, and multimap in STL use a very efficient balanced retrieval binary tree: red-black tree, also known as RB tree
(Red-Black Tree). The statistical performance of RB tree is better than that of general balanced binary tree, so it is selected by STL as the internal structure of associative container.
Because it is sorted, the elements in the set cannot be modified, they can only be deleted and then added.
3、

Commonly used methods in set

c++ stl container set member function: begin()--returns an iterator pointing to the first element

c++ stl container set member function: clear()--clear all elements

c++ stl container set member function: count()-- used to find the number of occurrences of a certain key value in the set. This function is not very useful in sets, because a key value can only appear in the set

                      0 or 1 time, so it becomes a judgment of whether a key value has appeared in the set.

c++ stl container set member function: empty()--If the set is empty, return true

c++ stl container set member function: end()--returns an iterator pointing to the last element

c++ stl container set member function: equal_range()--returns two iterators of the upper and lower bounds equal to the given value in the set

c++ stl container set member function: erase()--delete elements in the set

c++ stl container set member function: find()--returns an iterator pointing to the element found

c++ stl container set member function: get_allocator()--returns the allocator of the set

c++ stl container set member function: insert()--insert elements in the collection

c++ stl container set member function: lower_bound()--returns an iterator pointing to the first element greater than (or equal to) a value

c++ stl container set member function: key_comp()--returns a function for value comparison between elements

c++ stl container set member function: max_size()--returns the maximum limit of the elements that the set can hold

c++ stl container set member function: rbegin()--returns a reverse iterator pointing to the last element in the set

c++ stl container set member function: rend()--returns a reverse iterator pointing to the first element in the set

c++ stl container set member function: size()--the number of elements in the set

c++ stl container set member function: swap()--exchange two set variables

c++ stl container set member function: upper_bound()--returns an iterator of elements greater than a certain value

c++ stl container set member function: value_comp()--returns a function for comparing the values ​​between elements

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326804763&siteId=291194637