-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcyclearr.cs
45 lines (35 loc) · 862 Bytes
/
cyclearr.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
// To execute C#, please define "static void Main" on a class
// named Solution.
class Solution
{
static void Main(string[] args)
{
int[] arr = new int[7] {1,2,3,4,5,6,7};
int d = 2;
int length = arr.Length;
cyclearr(arr, d);
for(int i=0; i<length; i++)
{
Console.Write(arr[i] + " ");
}
}
public static void cyclearr(int[] arr, int d)
{
for(int i=0; i<d; i++)
{
cyclearrbyOne(arr);
}
}
public static void cyclearrbyOne(int[] arr)
{
int length = arr.Length;
int temp = arr[length -1];
int i = length -1;
for(i = length -1; i>0; i--)
{
arr[i] = arr[i-1];
}
arr[0] = temp;
}
}