C++ Algorithm Function equal()30 Aug 2024 | 2 min read C++ Algorithm equal()function compares the elements in both the containers and returns a true value if all the elements in both the containers are found to be matching. The first range is from [first1,last1) and the second starts from first2. SyntaxParameterfirst1: It is an input iterator to the first element of the [first1, last1). last1: It is an input iterator to the last element of the [first1, last1). first2: It is an input iterator to the first element of the [first2, last2). pred: It is a binary function that accepts two elements as arguments and performs the task designed by the function. Return valueThe function returns the value true if all the elements in both the containers match, otherwise it returns false. Example 1Output: Both the containers have matching elements. Both the containers do not have equal elements. Example 2Output: The vector consists of: 10, 20,30,40,50 Both the containers have equal elements. ComplexityThe function has linear complexity from the first1 element to the last1 element. Data racesObjects in both ranges are accessed. ExceptionsThe function throws an exception if any of the argument throws one. Next TopicC++ Algorithm find Function |
C++ Algorithm Function any_of() C++ Algorithm any_of() function tests the value of 'pred' for every element in the range, if for any element the value of pred is true, then the function returns true else return false. Syntax template <class InputIteratir, class UnaryPredicate> bool any_of (InputIterator first, InputIterator last, UnaryPredicate...
1 min read
C++ Algorithm equal_range() C++ Algorithm equal_range() function is the version of binary search. This function is used to return the lower bound and upper bound of the sub range that includes all the elements equivalent to val in the range [first, last). Where sub range is defined...
7 min read
C++ Algorithm fill_n() C++ Algorithm fill_n() function is used to assign a new value to a specified number of elements in a range beginning with a particular element. It means in fill_n(), we specify beginning position, number of elements to be filled and value to be filled. Syntax template <class...
4 min read
C++ Algorithm shuffle() C++ Algorithm shuffle() function reorders the elements of a range by putting them at random places, using g as uniform random number generator. Syntax template <class RandomAccessIterator, class URNG> void shuffle (RandomAccessIterator first, RandomAccessIterator last, URNG&& g); Parameter first: A random access iterator pointing the position of...
2 min read
C++ Algorithm Functions all_of() C++ Algorithm all_of() function returns a true value if the value of 'pred' argument is true. The value should be true for all elements in the range [first, last]. Syntax template <class InputIterator, class UnaryPredicate> bool all_of (InputIterator first, InputIterator last, UnaryPredicate pred); Parameter first: It specifies the...
1 min read
C++ Algorithm Functions none_of() C++ Algorithm none_of() function returns a true value if the value of 'pred' argument is false. The value should be false for all elements in the range [first, last). Syntax template <class InputIterator, class UnaryPredicate> bool none_of (InputIterator first, InputIterator last, UnaryPredicate pred); Parameter first : It specifies...
2 min read
C++ Algorithm upper_bound() C++ Algorithm upper_bound() function is the version of binary search. This function is used to return an iterator pointing to the first element in the range [first, last) that is greater than to the specified value val. The first version uses operator < to compare...
5 min read
C++ Algorithm stable_partition() C++ Algorithm stable_partition() function is used to classify the elements in the range [first, last), in such a way that all the elements for which pred returns true precede all those for which it returns false, where the relative order of elements is preserved. Note:...
4 min read
C++ Algorithm random_shuffle() C++ Algorithm random_shuffle() reorders the elements of a range by putting them at random places. The first version uses an internal random number generator and the second version uses a random number generator which is a special kind of function object that is explicitly...
4 min read
C++ Algorithm sort() C++ Algorithm sort() function is used to sort the elements in the range [first, last) into ascending order. The elements are compared using operator < for the first version, and comp for the second version. Syntax default (1) template <class RandomAccessIterator> void sort (RandomAccessIterator first, RandomAccessIterator last); custom...
5 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