Container learning set multiset

Container set and multiset

The third time I have written off again nothing open the

 

Why are they: are two principles to some sort sorts the elements of the container

Sort principles default

You can write their own (and I guess it should be a priority queue structure as write their own sort)

 

Difference: set multiset can not tolerate the same element

(Why do I want to set, multiset are not using it, of course not ...)

 

Features:

1. They do not provide for direct access to how the elements

(For example, a part of: that is, you can not directly modify the value inside the container, put this value into the value of the new pop-up.)

2. They accessing elements through iterator

Header file: include <set> // Both are the first document oh family thing. .

 

Operation: (set and multiset so I just write the same set of, multiset multiset instead put the set like)

(Some operations do not use but are afraid of the future met I write here)

These mainly to build

0.set <int> a; // int define a type of container a

1.set a; // generates an empty set

2.set a (op) // op to sort prevail produce an empty set (op has a default rule, but also its own heavy-duty rule)

3.set a1 (a2) // produce a copy of all the elements are the same

4.set a (beg, end) // interval [beg, end) generating a set of elements

5.set a (beg, end, op) // subject to the same sort op 4 ...

6.c. ~ set () // destroy all elements of free memory

7.set <Elem> // to operator <sorting subject, generating a set

8.set <Elem, op> // sort op subject to generate a set

 

These are not changes to the main

A set of a set

9. a.size () // Returns the current number of elements

10. a.empty () // set size determination is 0 (that is, determines a.size () is equal to zero)

11. a.max_size () // Returns the maximum number of elements can accommodate

 

These are the iterator correlation function (characteristics mentioned earlier, the algorithm can not call volatility)

set and multiset are bidirectional iterators

12. a.begin () // return the first element of the container 

13. a.end () // next position is not the last element of the return vessel chant so to find the last element --a.end () on the line

14. a.rbegin () // returns reverse iterator to the first element

15. a.rend () // Returns next position reverse iterator to the last element

 

These mainly a function (Search-based)

A set of a set

The number of elements 16. (elem) // returns the element value elem a.count

17. a.find (elem) // returns the element value of the element elem, if found elem return a.end ()

Position 18. lower_bound (elem) // returns first one placement element position value elem element value is> = the first element of elem

19. upper_bound (elem) // Returns the value of the last elements of a placement element value is the position of elem> elem position of the first element

20. equal_range (elem) // return the first position can be placed elem, i.e. element values ​​== interval elem

 

These are the assignments

Set a1, a2 is set

21. a1 = a2 // gave the elements a1 a2

22. a1.swap (a2) // a1 and a2 of the interchangeable element

 

These are the insertions and deletions (Some did not write)

23. a.insert (elem) // insert an element

24. a.erase // all elements (elem) equal deletes elem, returns the number of elements to be deleted

25 a.erase (pos) // delete iterator pos position of the element within the meaning of no return value

Is in front of those iterators related functions

For example a.erase (- a.end ()) to delete the last element of the container

26 a.insert (pos, elem) // Why is this written on the back 25 Hey, you know it is all right pos pos from the beginning of the search to insert an element which can improve the efficiency of it. .

27  a.clear()  //移除所有元素,把容器清空

 

好了容器空了 我就不写了

Guess you like

Origin www.cnblogs.com/Bellmond/p/12427428.html