Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 214a0bc

Browse files
Create CyclicallyRotateArray.java
1 parent 34d6359 commit 214a0bc

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎PraticeQues/CyclicallyRotateArray.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package LoveBabbarDSA;// { Driver Code Starts
2+
//Initial Template for Java
3+
4+
import java.lang.*;
5+
import java.io.*;
6+
7+
class CyicallyRotateAnArray {
8+
public static void main(String[] args) throws IOException
9+
{
10+
BufferedReader br =
11+
new BufferedReader(new InputStreamReader(System.in));
12+
int t =
13+
Integer.parseInt(br.readLine().trim()); // Inputting the testcases
14+
while(t-->0)
15+
{
16+
int n = Integer.parseInt(br.readLine().trim());
17+
int a[] = new int[n];
18+
// long getAnswer[] = new long[(int)(n)];
19+
String inputLine[] = br.readLine().trim().split(" ");
20+
for (int i = 0; i < n; i++) {
21+
a[i] = Integer.parseInt(inputLine[i]);
22+
}
23+
24+
Compute obj = new Compute();
25+
obj.rotate(a, n);
26+
27+
StringBuilder output = new StringBuilder();
28+
for(int i=0;i<n;i++)
29+
output.append(a[i]+" ");
30+
System.out.println(output);
31+
32+
}
33+
}
34+
}
35+
36+
// } Driver Code Ends
37+
38+
39+
//User function Template for Java
40+
41+
class Compute {
42+
43+
public void rotate(int arr[], int n)
44+
{
45+
int t = arr[n - 1];
46+
for (int i = n - 1;i > 0;i--) {
47+
// int c = arr[i];
48+
arr[i] = arr[i - 1];
49+
}
50+
arr[0] = t;
51+
}
52+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /