We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f77f5e6 commit 03edbe5Copy full SHA for 03edbe5
partail left(second half).java
@@ -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