19 set and multiset of standard template library STL

basic knowledge

        1. Set is a container that is automatically ordered and does not contain repeated elements. It is implemented internally using the data structure of a balanced binary index tree of a red-black tree. When inserting a new element into the set, the arrangement of the binary tree will be automatically adjusted, and the element will be placed in a suitable position. The difference between multiset and set is that elements of the same value in set can only appear once, and elements of the same value in multiset can appear multiple times.

        2. When inserting elements into the set/multiset, the set/multiset will be automatically arranged in ascending order, and elements cannot be inserted at the specified position of the set/multiset. When inserting duplicate elements into the set, it will be ignored, while in multiset, duplicate elements are allowed to be inserted.

        3. Before using set and multiset, you need to include their header files.

#include <set>
using namespace std;

        The main interfaces provided by the set and multiset containers can be found in the table below.

interface

Remark

size()

Returns the number of elements in the set/multiset

empty()

Determine whether the set/multiset is empty, and return tr if it is empty

Guess you like

Origin blog.csdn.net/hope_wisdom/article/details/130303232