C++ Algorithm rotate_copy()30 Aug 2024 | 5 min read C++ Algorithm rotate_copy() function is used to make a rotated copy of the elements in the range [first, last).
SyntaxParameterfirst: A forward iterator pointing the position of the first element in the range to be rotated. middle: A forward iterator addressing to the element within the range [first, last) that is moved to the first position in the range. last: A forward iterator pointing the position one past the final element in the range in which the elements are being reversed. result: An output iterator pointing the position of the first element in the destination range. Return valuerotate_copy() function returns an output iterator addressing to the end of the copied range. ComplexityComplexity is linear in the range [first, last): performs an assignment for each element. Data racesThe object in the range [first, last) are accessed. The object in the range between result and the returned value are changed. ExceptionsThis function throws an exception if either an element assignment or an operation on iterator throws an exception. Note: The invalid parameters cause an undefined behavior.Example 1Let's see the simple example to rotate the given string: Output: Before Rotate : N I K I T A After Rotate : I K I T A N Example 2Let's see another simple example: Output: 3 4 5 1 2 Example 3Let's see another simple example: Output: Character array s[] : 1. A 2. B 3. C 4. D 5. E 6. F 7. G 8. H Rotate s[] with 'C' as middle element and copy in t[] Character array t[] : 1. C 2. D 3. E 4. F 5. G 6. H 7. A 8. B Rotate t[] with 'A' as middle element and copy in s[] Character array s[] : 1. A 2. B 3. C 4. D 5. E 6. F 7. G 8. H Character array t[] : 1. C 2. D 3. E 4. F 5. G 6. H 7. A 8. B Example 4Let's see another simple example: Output: Before calling rotate_copy: Try this Tongue Twister: she sells sea shells by the sea shore After calling rotate_copy: Tongue_Twister: she sells sea shells by the sea shore Now try the rotated Tongue Twister: shells by the sea shore she sells sea Next TopicC++ Algorithm |
C++ Algorithm max() C++ Algorithm max() function can be used in following 3 ways: It compares the two values passed in its arguments and returns the larger between them. If both are equal, then it returns the first one. It also compares the two values using a binary...
5 min read
C++ Algorithm Function copy() C++ Algorithm copy() function is used to copy all the elements of the container [first,last] into a different container starting from result. Syntax template<class InputIterator, class OutputIterator>OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result); Parameter first: It is an input iterator to the first element of the range,...
1 min read
C++ Algorithm Function find_if() C++ Algorithm find_if() function returns the value of the first element in the range for which the pred value is true otherwise the last element of the range is given. Syntax template <class InputIterator, class UnaryPredicate> InputIterator find_if (InputIterator first, InputIterator last, UnaryPredicate pred); Parameter first: It specifies...
2 min read
C++ Algorithm replace_if() C++ Algorithm replace_if() function is used to assign new_value to all the elements in the range [first, last) for which pred predicate returns true. This function examines each element in a range and replaces it if it satisfies a specified predicate. Syntax template <class ForwardIterator,...
4 min read
C++ Algorithm Function find_end () C++ Algorithm find_end()function searches for the last occurrence of a pattern in the container, or say the last occurrence of a small portion of the sequence in the container. It basically searches the range specified by [first1,last1)for the occurrence of sequence which...
2 min read
C++ Algorithm remove_if() C++ Algorithm remove_if() function is used to eliminate all the elements that satisfy a predicate from a given range [first, last) without disturbing the order of the remaining elements. This function cannot alter the size of the container. It returns an iterator to the new end...
6 min read
C++ Algorithm Function search() C++ Algorithm search() function searches the range [first1, last1) for the occurrence of a subsequence defined by the range [first2, last2), and an iterator to the first element is returned. If the subsequence does not exist then an iterator to the last1 is...
2 min read
C++ Algorithm swap() Function C++ Algorithm swap() function swaps or say interchanges the values of two containers under reference. Syntax template<class T> void swap(T& a, T& b); Parameter a: It is the first container with some value. b: It is another container with some value. Return value The function only swaps the values of...
2 min read
C++ Algorithm _permutation () C++ Algorithm _permutation() function is used to reorder the elements in the range [first, last) into the lexicographically greater permutation. A permutation is specified as each of several possible ways in which a set or number of things can be ordered or...
6 min read
C++ Algorithm Function for_each() C++ Algorithm for_each() function applies the function func to all of the elements in the range from 'first' to 'last'. Syntax template <class InputIterator, class Function> Function for_each (InputIterator first, InputIterator last, Function func); Parameter first: It specifies the first element in the list. last: It specifies the...
4 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