Skip to content

Commit d6e6780

Browse files
committed
add: Documetation
1 parent 6df8c14 commit d6e6780

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/main/java/com/thealgorithms/others/ArrayRightRotation.java

+21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
package com.thealgorithms.others;
22

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+
*/
310
public final class ArrayRightRotation {
411
private ArrayRightRotation() {
512
}
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+
*/
621
public static int[] rotateRight(int[] arr, int k) {
722
if (arr == null || arr.length == 0 || k < 0) {
823
throw new IllegalArgumentException("Invalid input");
@@ -18,6 +33,12 @@ public static int[] rotateRight(int[] arr, int k) {
1833
return arr;
1934
}
2035

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+
*/
2142
private static void reverseArray(int[] arr, int start, int end) {
2243
while (start < end) {
2344
int temp = arr[start];

0 commit comments

Comments
 (0)