set and multiset in c++ STL

1. Structure

set and multiset sort the elements according to a specific ordering principle. The difference between the two is that multisets allow elements to be repeated, while sets do not.

The elements in the set can be of any type, but because they need to be sorted, the elements must have an order, that is, the comparison relationship of size, as long as the type T of assignable, copyable, and comparable (according to a certain sorting criterion) can become Elements of set or multisets.

2. The underlying implementation

Like all standard associative containers, sets and multisets are usually implemented as balanced binary trees.

The main advantage of automatic sorting is that it makes binary tree search elements have good performance, and its search function algorithm has logarithmic complexity. However, automatic sorting also creates a limitation. You cannot directly change the element value, because this will disrupt the original order. To change the value of the element, you must delete the old element first, and then insert the new element. So sets and multisets have the following characteristics:

*Does not provide any operation elements for direct access to elements

* Access elements through iterators.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324453468&siteId=291194637