C++ Algorithm rotate_copy()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 |
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