File tree 1 file changed +21
-0
lines changed
src/main/java/com/thealgorithms/others
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1
1
package com .thealgorithms .others ;
2
2
3
+ /**
4
+ * Provides a method to perform a right rotation on an array.
5
+ * A left rotation operation shifts each element of the array
6
+ * by a specified number of positions to the right.
7
+ *
8
+ * https://en.wikipedia.org/wiki/Right_rotation *
9
+ */
3
10
public final class ArrayRightRotation {
4
11
private ArrayRightRotation () {
5
12
}
13
+
14
+ /**
15
+ * Performs a right rotation on the given array by the specified number of positions.
16
+ *
17
+ * @param arr the array to be rotated
18
+ * @param k the number of positions to rotate the array to the left
19
+ * @return a new array containing the elements of the input array rotated to the left
20
+ */
6
21
public static int [] rotateRight (int [] arr , int k ) {
7
22
if (arr == null || arr .length == 0 || k < 0 ) {
8
23
throw new IllegalArgumentException ("Invalid input" );
@@ -18,6 +33,12 @@ public static int[] rotateRight(int[] arr, int k) {
18
33
return arr ;
19
34
}
20
35
36
+ /**
37
+ * Performs reversing of a array
38
+ * @param arr the array to be reversed
39
+ * @param start starting position
40
+ * @param end ending position
41
+ */
21
42
private static void reverseArray (int [] arr , int start , int end ) {
22
43
while (start < end ) {
23
44
int temp = arr [start ];
You can’t perform that action at this time.
0 commit comments