Write a method named rotateright that accepts an array of integers as a parameter and rotates the values in the array to the right (i.e., forward in position) by one. each element moves right by one, except the last element, which moves to the front. for example, if a variable named list refers to an array containing the values {3, 8, 19, 7}, the call of rotateright(list) should modify it to store {7, 3, 8, 19}. a subsequent call of rotateright(list) would leave the array as follows: {19, 7, 3, 8} */

Respuesta :

You should really state what language you are using. I have produced your method in C#, and should be easily translatable in to any other language.

static void RotateRight<T>(T[] arr)
{          
    T temp = arr[arr.Length - 1];
   
    for (int i = arr.Length - 1; i >= 0; i--)
    {               
        if (i == 0)                   
            arr[i] = temp;               
        else                   
            arr[i] = arr[i - 1];           
    }       
}