Skip to content

Commit dc82551

Browse files
checked with coding style issues
1 parent ddcac94 commit dc82551

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

src/main/java/com/thealgorithms/shufflealogrithm/ConstrainedShuffle.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
public class ConstrainedShuffle {
88

9+
private ConstrainedShuffle() {
10+
// Prevent instantiation
11+
}
12+
913
/**
1014
* Shuffles the array so that no element stays in its original position.
1115
*

src/main/java/com/thealgorithms/shufflealogrithm/GroupShuffle.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
public class GroupShuffle {
88

9+
private GroupShuffle() {
10+
// Prevent instantiation
11+
}
12+
913
/**
1014
* Divides the array into k equal-sized groups and shuffles each group separately.
1115
* Returns an empty list if the group count exceeds the array length.

src/main/java/com/thealgorithms/shufflealogrithm/ShuffleByRange.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
public class ShuffleByRange {
66

7+
private ShuffleByRange() {
8+
// Prevent instantiation
9+
}
10+
711
/**
812
* Shuffles elements within a specified index range, leaving elements outside this range unchanged.
913
*

src/main/java/com/thealgorithms/shufflealogrithm/UnderstandingShuffleAlgo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
public class UnderstandingShuffleAlgo {
66

7+
private UnderstandingShuffleAlgo() {
8+
// Prevent instantiation
9+
}
10+
711
/**
812
* Shuffles the elements in the array randomly.
913
* Uses a method that gives each item an equal chance to appear in any position.

src/main/java/com/thealgorithms/shufflealogrithm/UniquePairShuffle.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
public class UniquePairShuffle {
88

9+
private UniquePairShuffle() {
10+
// Prevent instantiation
11+
}
12+
913
/**
1014
* Pairs each element in the array with another element randomly, ensuring no pair repeats.
1115
* If the array length is odd, pairing cannot be completed, so an empty list is returned.
@@ -17,7 +21,9 @@ public static List<int[]> pairShuffle(int[] array) {
1721
List<int[]> pairs = new ArrayList<>();
1822

1923
// Handle edge case: If the array length is odd, pairing is not possible
20-
if (array.length % 2 != 0) return pairs;
24+
if (array.length % 2 != 0) {
25+
return pairs;
26+
}
2127

2228
List<Integer> shuffledList = new ArrayList<>();
2329
for (int num : array) {

src/main/java/com/thealgorithms/shufflealogrithm/WeightedShuffle.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
public class WeightedShuffle {
77

8+
private WeightedShuffle() {
9+
// Prevent instantiation
10+
}
11+
812
/**
913
* Shuffles elements based on their weights. Higher weight elements are more likely to appear earlier.
1014
*
@@ -13,7 +17,9 @@ public class WeightedShuffle {
1317
*/
1418
public static void weightedShuffle(int[] array, int[] weights) {
1519
// Edge case: Check if weights match the array size
16-
if (array == null || weights == null || array.length != weights.length) return;
20+
if (array == null || weights == null || array.length != weights.length) {
21+
return;
22+
}
1723

1824
Integer[] indices = new Integer[array.length];
1925
for (int i = 0; i < array.length; i++) {

0 commit comments

Comments
 (0)