C++ set crend()30 Aug 2024 | 3 min read C++ set crend() function is used to return a constant iterator to the end of the set (not the last element but the past last element) in reverse order. This is similar to the element preceding the first element of the non-reversed container. Note:- This is a placeholder. No element exists in this location and attempting to access is undefined behavior.A constant iterator is an iterator that points to the constant content. SyntaxParameterNone Return valueIt returns a const_reverse_iterator to the element following the last element of the reversed container. ComplexityConstant. Iterator validityNo changes. Data RacesThe container is accessed. Concurrently accessing the elements of a set is safe. Exception SafetyThis function never throws exception. Example 1Let's see the simple example for crend() function: Output: myset in reverse order: 50 40 30 20 10 In the above example, crend() function is used to return a constant reverse iterator to the element following the last element of the reversed container. Because set stores the elements in sorted order of keys therefore, iterating over a set will result in above order i.e. sorted order of keys. Example 2Let's see a simple example to iterate over the set in reverse order using while loop: Output: ddd ccc bbb aaa In the above example, we are using while loop to const_iterate over the set in reverse order. Because set stores the elements in sorted order of keys therefore, iterating over a set will result in above order i.e. sorted order of keys. Example 3Let's see a simple example: Output: 3 2 1 In the above example, elements of set returned in reverse order. Example 4Let's see a simple example to sort and calculate the highest marks: Output: Salary ______________________ 4500 3000 2500 1200 1000 Highest salary: 4500 In the above example, a set emp is implemented where salary is stored as key. This enables us to take advantage of the auto sorting of salary in set and lets us to identify the highest salary. Next TopicSet empty() Function |
set find() function
C++ set find() C++ is used to find an element with the given value val. If it finds the element then it returns an iterator pointing to the element otherwise, it returns an iterator pointing to the end of the set i.e. set::end(). Syntax ...
3 min read
set empty() function
C++ set empty() C++ empty() function is used to check whether the set container is empty or not. It returns true if the set container is empty (size is 0) otherwise, it returns false. Syntax bool empty() const; ...
3 min read
set rbegin() function
C++ set rbegin() C++ is used to return a reverse iterator referring to the last element of the set container. A reverse iterator of set moves in reverse direction and incrementing it until it reaches to the beginning (First element) of the set container. Syntax ...
4 min read
set operator=() function
C++ set operator= There are following three uses of operator= in set: Operator= is used to assign new content to the set container by replacing its old content (or copy the content) and modifies size if necessary. Operator= is used to move the content of one set container into...
4 min read
C++ Set
C++ STL Set Introduction to set Sets are part of the C++ STL (Standard Template Library). Sets are the associative containers that stores sorted key, in which each key is unique and it can be inserted or deleted but cannot be altered. Syntax template < class T, ...
2 min read
set operator>=
C++ std operator>= C++ std Operator>= is a non-member overloaded function of set in C++. This function is used to check whether the first set is greater than or equal to other or not. Note: Operator >= sequentially compares the element of set and comparison will stop at...
5 min read
set count() function
C++ set count() C++ is used to return the number of elements found in the container. Since, the set container does not contain any duplicate element, this function actually returns 1 if the element with value val is present in the set container or 0 otherwise....
4 min read
set equal_range() function
C++ set equal_range() C++ is used to return the boundary of the range containing all elements in the container that are equal to val. Since there is no duplication of values in the set container, this range includes at most one element. If val does not...
5 min read
set crbegin() function
C++ set crbegin() C++ is used to return a constant reverse iterator referring to the last element in the set container. A constant reverse iterator of set moves in reverse direction and incrementing it until it reaches to the beginning (First element) of the set container and...
3 min read
set Size() function
C++ set size() C++ set size() function is used to find the number of elements present in the set container. Syntax Member type size_type is an unsigned integral type. size_type size() const; // until C++ 11 size_type...
3 min read
We request you to subscribe our newsletter for upcoming updates.

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