Javatpoint Logo
Javatpoint Logo

C++ multiset upper_bound()

C++ Multiset upper_bound() function is used to return an iterator pointing to the value in the multiset container which is larger to val passed in the parameter.

Syntax

Parameter

val: value to be searched in the multiset container.

Return value

upper_bound() function returns an iterator pointing to the value in the multiset container which is larger to val passed in the parameter. If there is no such element return end().

Complexity

Logarithmic in size.

Iterator validity

No changes.

Data Races

The container is accessed (neither the const nor the non-const versions modify the multiset container).

Concurrently accessing the elements of container is safe.

Exception

If an exception is thrown, there are no changes in the multiset.

Example 1

Let's see the simple example to get the upper bound of given value:

Output:

Upper bound of b is(>): c

In the above example, when we try to find the upper bound of element b then it will return greater element of b i.e. c

Example 2

Let's see a simple example to erase the element of multiset from lower bound to upper bound:

Output:

mymultiset contains: 10 20 70 80 90

In the above example, erase() function erased the element of multiset from lower bound(=) to upper bound(>) and print the remaining content.

Example 3

Let's see a simple example:

Output:

The upper bound of key 11 is 12
The upper bound of key 13 is 14
The upper bound of key 17 is 4

In the above example, when we try to find the upper bound of a value which is not present in the multiset container but does not exceed the maximum value then it will return greater value

i.e. when we trying to find upper bound of 13 then it will return 14 and when we trying to find upper bound of a value which is not present in the multiset and exceeds the maximum value of container then it will return to the end().

Example 4

Let's see a simple example:

Output:

The first element of multiset s1 with a key greater than 20 is: 30.
The multiset s1 doesn't have an element with a key greater than 30.
The first element of s1 with a key greater than
that of the initial element of s1 is: 20.
Next TopicC++ multiset




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA