0% found this document useful (0 votes)
11 views4 pages

CPP Multiset Library Methods

The C++ <multiset> library provides various methods for managing ordered multisets that allow duplicate elements. Key methods include constructors, insertion, deletion, searching, and counting elements, as well as utilities for checking size and emptiness. Additional functionalities include iterators for traversing the multiset and methods for element manipulation such as emplace and swap.

Uploaded by

saeednabawy950
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

CPP Multiset Library Methods

The C++ <multiset> library provides various methods for managing ordered multisets that allow duplicate elements. Key methods include constructors, insertion, deletion, searching, and counting elements, as well as utilities for checking size and emptiness. Additional functionalities include iterators for traversing the multiset and methods for element manipulation such as emplace and swap.

Uploaded by

saeednabawy950
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

C++ Multiset Library Methods

The <multiset> library in C++ provides a collection of methods for managing ordered multisets ofelements,

where duplicate elements are allowed. Below is a list of the common methods available, along withtheir

arguments and usage examples.

1. Constructor

- multiset<T>()

- multiset<T>(initializer_list<T>)

- multiset<T>(const multiset<T>&)

- multiset<T>(multiset<T>&&)

- Description: Constructs a new multiset.

2. insert()

- Arguments: const T& value, T&& value

- Usage: Inserts an element into the multiset, allowing duplicates.

- Example: multiset.insert(10);

3. erase()

- Arguments: iterator pos, const T& value, iterator first, iterator last

- Usage: Removes an element or a range of elements from the multiset.

- Example: multiset.erase(10);

-
4. find()

- Arguments: const T& value

- Usage: Searches the multiset for an element with a specific value.

- Example: auto it = multiset.find(10);


5. count()

- Arguments: const T& value

- Usage: Counts the occurrences of an element in the multiset.

- Example: size_t count = multiset.count(10);

6. size()

- Arguments: None

- Usage: Returns the number of elements in the multiset.

- Example: size_t size = multiset.size();

7. empty()

- Arguments: None

- Usage: Checks if the multiset is empty.

- Example: bool isEmpty = multiset.empty();

8. clear()

- Arguments: None

- Usage: Removes all elements from the multiset.

- Example: multiset.clear();

9. begin()

- Arguments: None

- Usage: Returns an iterator to the first element in the multiset.

- Example: auto it = multiset.begin();

10. end()

- Arguments: None

- Usage: Returns an iterator to the past-the-end element in the multiset.

- Example: auto it = multiset.end();


11. rbegin()

- Arguments: None

- Usage: Returns a reverse iterator to the first element of the reversed multiset.

- Example: auto rit = multiset.rbegin();

12. rend()

- Arguments: None

- Usage: Returns a reverse iterator to the past-the-end element of the reversed multiset.

- Example: auto rit = multiset.rend();

13. max_size()

- Arguments: None
- Usage: Returns the maximum number of elements the multiset can hold.

- Example: size_t maxSize = multiset.max_size();

14. swap()

- Arguments: multiset<T>& other

- Usage: Swaps the contents of two multisets.

- Example: multiset1.swap(multiset2);

15. emplace()

- Arguments: Args&&... args

- Usage: Constructs and inserts an element in-place into the multiset.

- Example: multiset.emplace(10);

16. emplace_hint()

- Arguments: const_iterator position, Args&&... args

- Usage: Constructs and inserts an element in-place at a specific position.

- Example: multiset.emplace_hint(multiset.begin(), 10);


17. equal_range()

- Arguments: const T& value

- Usage: Returns a range of elements that are equivalent to a specific value.

- Example: auto range = multiset.equal_range(10);

18. lower_bound()
- Arguments: const T& value

- Usage: Returns an iterator pointing to the first element not less than the given value.

- Example: auto it = multiset.lower_bound(10);

19. upper_bound()

- Arguments: const T& value

- Usage: Returns an iterator pointing to the first element greater than the given value.

- Example: auto it = multiset.upper_bound(10);

You might also like