Skip to content

Latest commit

 

History

History

rightShift

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Right shift algorithm

Time: formula Space: formula

void rightShift(int a[], int n, int d){
    int i, b[n];
    for(i=0;i<n;i++){
        if(i+d>=n)
            b[i+d-n]=a[i]; 
        else
            b[i+d]=a[i];
    }
    for(i=0;i<n;i++)
        a[i] = b[i];
    for(i=0;i<n;i++)
        cout<<a[i]<<" ";
}