C++ set upper_bound()C++ set upper_bound() function is used to return an iterator pointing to the value in the set container which is larger to val passed in the parameter. SyntaxParameterval: value to be searched in the set container. Return valueIt returns an iterator pointing to the value in the set container which is larger to val passed in the parameter. If there is no such element return end(). ComplexityLogarithmic in size. Iterator validityNo changes. Data RacesThe container is accessed (neither the const nor the non-const versions modify the container). Concurrently accessing the elements of a set is safe. ExceptionIf an exception is thrown, there are no changes in the container. Example 1Let'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 2Let's see a simple example to erase the elements of set from lower bound to upper bound: Output: myset contains: 10 20 70 80 90 In the above example, erase() function erased the element of set from lower bound(=) to upper bound(>) and print the remaining content. Example 3Let'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 set container but does not exceeds 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 set and exceeds the maximum value of container then it will return to the end(). Example 4Let's see a simple example: Output: The first element of set s1 with a key greater than 20 is: 30. The set 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 TopicSet equal_range() Function |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India