-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlecture2_rightrotate.java
More file actions
31 lines (29 loc) · 905 Bytes
/
lecture2_rightrotate.java
File metadata and controls
31 lines (29 loc) · 905 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
public class lecture2_rightrotate{
//done modified
public static void main(String[] args) {
int[] source = {10, 20, 30, 40, 50};
int k = 3;
rightRotate(source, k);
print_array(source);
}
public static void rightRotate(int[] s,int shift) {
int[] temp = new int[shift];
for(int i = s.length-1, j = temp.length; i >=shift-1;i--, j--){
temp[j-1] = s[i];
if(i-shift>=0){
s[i] = s[i - shift];
}
}
// print_array(temp);
for(int mew = 0; mew < temp.length; mew++){
s[mew] = temp[mew];
}
}
public static void print_array(int[] y) {
System.out.println("Address of the source array: "+ y);
System.out.println("New right rotated array");
for(int value: y){
System.out.println(value);
}
}
}