Define a Multiset collection s:
Multiset <int> S;
If you have duplicate elements, be sure to remember to use MULTISET,STL set default from small to large, upper_bound (x) returns the address of the first element greater than x in the collection, Lower_bound (x) returns the address of the first element in the collection that is greater than or equal to X.
We can define an iterator like this: multiset<int>::iterator it;
It points to a memory address that we can make it=s.begin ();
If it is required to follow an element, it can be it++. Requires a precursor to it--。
If the first element less than or equal to X in the collection is required, it can be made: {It=s.upper_bound (X); it--;} (Be careful not to make it out of bounds)
S.insert (x)//Insert an element x
S.clear ()//emptying set S
S.size ()//Returns the number of elements in the collection
S.empty ()//returns a BOOL value indicating whether the collection is empty
Note: the erase () function is very pit.
S.erase (x) Delete the element on this memory address if X is the memory address of an element
If x is an element, delete all elements in s that are equal to this element (note that all)
From small to large traverse the entire set S
Multiset<int>::iterator it;
For (It=s.begin (); It!=s.end (); it++) {//note end condition is it!=s.end () instead of <
cout<< (*it) <<endl;
}
The last element in the collection s:
It=s.end (); it--; S.end () is not the address of the last element in S, so remember it--
cout<< (*it) <<endl;
C + + STL set User manual