2

Generic Right Shift (Id-1538)

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

Program ID- 1538

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

Code

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 

The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

 

Click Here to Leave a Comment Below 2 comments
da - March 31, 2019

code is not working

Reply
Aman - November 3, 2019

Yeah, it’s working, thanks a lot.

#include
using namespace std;
#include
template
//shift the set of ‘n’ elements ele by ‘r’ positions
void right_Shift(T *ele,int n,int r);
template 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>ch;
string s[10];
if(ch==0)
{
cin>>n;
for(int i=0;i>a[i];
cin>>r;
right_Shift(a,n,r);
for(int i=0;i<n;i++)
cout<<a[i]<>n;
for(int i=0;i>s[i];
cin>>r;
right_Shift(s,n,r);
for(int i=0;i<n;i++)
cout<<s[i]<<endl;
}
}

Reply

Leave a Reply:

This site uses cookies and by using the site you are consenting to this.