Skip to content

Commit 03edbe5

Browse files
Add files via upload
1 parent f77f5e6 commit 03edbe5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Diff for: partail left(second half).java

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.util.*;
2+
public class Main
3+
{
4+
public static void reverse(int arr[],int start,int end){
5+
while(start<end){
6+
int temp=arr[start];
7+
arr[start]=arr[end];
8+
arr[end]=temp;
9+
start++;
10+
end--;
11+
}
12+
}
13+
public static void rotate(int arr[],int size,int rot){
14+
int mid=size/2;
15+
int fhs=size-mid;
16+
rot=rot%fhs;
17+
18+
reverse(arr,0,rot-1);
19+
reverse(arr,rot,fhs-1);
20+
reverse(arr,0,fhs-1);
21+
22+
}
23+
public static void main(String[] args) {
24+
Scanner sc=new Scanner(System.in);
25+
int arr[]={1,2,3,4,5};
26+
int rot=sc.nextInt();
27+
int size=arr.length;
28+
29+
rotate(arr,size,rot);
30+
31+
for(int i=0;i<arr.length;i++){
32+
System.out.print(arr[i]+" ");
33+
}
34+
}
35+
}
36+

0 commit comments

Comments
 (0)