# Generic Right Shift (Id-1538)

**Just for Practice 6 Additional [26-Feb-2018 to 3-Mar-2018]**

Given a set of ‘n’ elements and ‘r’, write a generic function to right shift the set of elements by ‘r’ position. If the elements are to moved to position greater than ‘n’ then wrap the shift process to the beginning of the collection. For example, if the set of five elements are 1,7,8,9,12 and value of ‘r’ is 3 then the set of elements would be 8, 9, 12, 1, 7.

Input Format

Choice of data type (0 for integer and 1 for string)

Number of elements in the collection

Element1 in the collection

Element2 in the collection

….

Elementn in the collection

Value for ‘r’

Output Format

Elements in the collection after right shift

Element1

Element2

…

Elementn

**Please Comment** Working if the code worked to you

If you have other working codes please comment the codes enclosing with **<pre> **and** </pre>** 🙂

Example: <pre> Your Code </pre>

**C++ Code **

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | template<class T> void right_Shift(T *ele, int n, int r) { T *ne= new T[20]; int i=0; for(; i<n; i++) { ne[i]=ele[i]; } r=n-r; for(i=0; i<n; i++) { ele[i]=ne[(r+i)%n]; } } |

**reference**only. It doesn't mean everyone to directly copy/paste those codes.