-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayrotate1.java
More file actions
51 lines (42 loc) · 831 Bytes
/
Arrayrotate1.java
File metadata and controls
51 lines (42 loc) · 831 Bytes
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
46
47
48
49
50
51
class Arrayrotate1
{
void leftarry(int arr[], int d)
{
if (d == 0) {
return;
}
else {
int n = arr.length;
reverseArry(arr,0,d-1);
reverseArry(arr,d,n-1);
reverseArry(arr,0,n-1);
}
}
void reverseArry(int arr[], int start, int end)
{
int temp;
while (start < end ) {
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
void printarry(int arr[])
{
for (int i=0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
public static void main(String args[])
{
Arrayrotate1 rotate = new Arrayrotate1();
int arr[] = {1,2,3,4,5,6,7,8,9};
int d=2;
int n = arr.length;
d = d%n;
rotate.leftarry(arr, d);
rotate.printarry(arr);
}
}