I have to rotate the array I imputed n number of places(I also select that) and I did that... but I have messed something up and Im not sure how to fix it. If you have seen some of this code online, sorry im not that good at it so I use google to help myself.
The results should be like this:
-input: 15 5 8 19 9 10
n:4
-output: 8 19 9 10 15 5
-input: 11 4 12 17 18 7 8 16
n:2
-output: 8 16 11 4 12 17 18 7
public static class Homework
{
static void RightRotate(int[] arr, int d,int n)
{
for (int i = 0; i < d; i++)
RightRotatebyOne(arr, n);
}
static void RightRotatebyOne(int[] arr, int n)
{
int i, temp = arr[0];
for (i = 0; i < n - 1; i++)
arr[i] = arr[i + 1];
arr[i] = temp;
}
static void printArray(int[] arr, int size)
{
for (int i = 0; i < size; i++)
Console.Write(arr[i] + " ");
}
static void Main(string[] args)
{
var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
int a = arr.Length;
int n = Convert.ToInt32(Console.ReadLine());
RightRotate(arr, n, a);
printArray(arr, a);
}
}
}
Edit: I dont know if its the same or not. I just dont know how to do it.