Skip to content

Commit df5d877

Browse files
author
Samuel Facchinello
committed
Merge branch 'master' into cleanup_Combination
2 parents d10c568 + cdb3aff commit df5d877

File tree

73 files changed

+741
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+741
-375
lines changed

checkstyle.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@
152152

153153
<!-- Checks for blocks. You know, those {}'s -->
154154
<!-- See https://checkstyle.org/checks/blocks/index.html -->
155-
<!-- TODO <module name="AvoidNestedBlocks"/> -->
155+
<module name="AvoidNestedBlocks"/>
156156
<!-- TODO <module name="EmptyBlock"/> -->
157157
<!-- TODO <module name="LeftCurly"/> -->
158-
<!-- TODO <module name="NeedBraces"/> -->
158+
<module name="NeedBraces"/>
159159
<!-- TODO <module name="RightCurly"/> -->
160160

161161
<!-- Checks for common coding problems -->

src/main/java/com/thealgorithms/backtracking/MColoring.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ static int possiblePaint(ArrayList<Node> nodes, int n, int m) {
5959
// If number of colors used exceeds m,
6060
// return 0
6161
maxColors = Math.max(maxColors, Math.max(nodes.get(top).color, nodes.get(it).color));
62-
if (maxColors > m) return 0;
62+
if (maxColors > m) {
63+
return 0;
64+
}
6365

6466
// If the adjacent node is not visited,
6567
// mark it visited and push it in queue

src/main/java/com/thealgorithms/backtracking/WordSearch.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ private boolean doDFS(int x, int y, int nextIdx) {
5151
int yi = y + dy[i];
5252
if (isValid(xi, yi) && board[xi][yi] == word.charAt(nextIdx) && !visited[xi][yi]) {
5353
boolean exists = doDFS(xi, yi, nextIdx + 1);
54-
if (exists) return true;
54+
if (exists) {
55+
return true;
56+
}
5557
}
5658
}
5759
visited[x][y] = false;
@@ -66,7 +68,9 @@ public boolean exist(char[][] board, String word) {
6668
if (board[i][j] == word.charAt(0)) {
6769
visited = new boolean[board.length][board[0].length];
6870
boolean exists = doDFS(i, j, 1);
69-
if (exists) return true;
71+
if (exists) {
72+
return true;
73+
}
7074
}
7175
}
7276
}

src/main/java/com/thealgorithms/ciphers/Blowfish.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,9 @@ private String hexToBin(String hex) {
11041104
private String binToHex(String binary) {
11051105
long num = Long.parseUnsignedLong(binary, 2);
11061106
String hex = Long.toHexString(num);
1107-
while (hex.length() < (binary.length() / 4)) hex = "0" + hex;
1107+
while (hex.length() < (binary.length() / 4)) {
1108+
hex = "0" + hex;
1109+
}
11081110

11091111
return hex;
11101112
}
@@ -1120,7 +1122,9 @@ private String xor(String a, String b) {
11201122
a = hexToBin(a);
11211123
b = hexToBin(b);
11221124
String ans = "";
1123-
for (int i = 0; i < a.length(); i++) ans += (char) (((a.charAt(i) - '0') ^ (b.charAt(i) - '0')) + '0');
1125+
for (int i = 0; i < a.length(); i++) {
1126+
ans += (char) (((a.charAt(i) - '0') ^ (b.charAt(i) - '0')) + '0');
1127+
}
11241128
ans = binToHex(ans);
11251129
return ans;
11261130
}
@@ -1202,7 +1206,9 @@ String encrypt(String plainText, String key) {
12021206
// generating key
12031207
keyGenerate(key);
12041208

1205-
for (int i = 0; i < 16; i++) plainText = round(i, plainText);
1209+
for (int i = 0; i < 16; i++) {
1210+
plainText = round(i, plainText);
1211+
}
12061212

12071213
// postprocessing
12081214
String right = plainText.substring(0, 8);
@@ -1224,7 +1230,9 @@ String decrypt(String cipherText, String key) {
12241230
// generating key
12251231
keyGenerate(key);
12261232

1227-
for (int i = 17; i > 1; i--) cipherText = round(i, cipherText);
1233+
for (int i = 17; i > 1; i--) {
1234+
cipherText = round(i, cipherText);
1235+
}
12281236

12291237
// postprocessing
12301238
String right = cipherText.substring(0, 8);

src/main/java/com/thealgorithms/ciphers/a5/A5KeyStreamGenerator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public void reInitialize() {
3131
}
3232

3333
public BitSet getNextKeyStream() {
34-
for (int cycle = 1; cycle <= INITIAL_CLOCKING_CYCLES; ++cycle) this.clock();
34+
for (int cycle = 1; cycle <= INITIAL_CLOCKING_CYCLES; ++cycle) {
35+
this.clock();
36+
}
3537

3638
BitSet result = new BitSet(KEY_STREAM_LENGTH);
3739
for (int cycle = 1; cycle <= KEY_STREAM_LENGTH; ++cycle) {

src/main/java/com/thealgorithms/ciphers/a5/CompositeLFSR.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public boolean clock() {
1919
boolean result = false;
2020
for (var register : registers) {
2121
result ^= register.getLastBit();
22-
if (register.getClockBit() == majorityBit) register.clock();
22+
if (register.getClockBit() == majorityBit) {
23+
register.clock();
24+
}
2325
}
2426
return result;
2527
}

src/main/java/com/thealgorithms/datastructures/buffers/CircularBuffer.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ public boolean isFull() {
2424
}
2525

2626
public Item get() {
27-
if (isEmpty()) return null;
27+
if (isEmpty()) {
28+
return null;
29+
}
2830

2931
Item item = buffer[getPointer.getAndIncrement()];
3032
size.decrementAndGet();
3133
return item;
3234
}
3335

3436
public boolean put(Item item) {
35-
if (isFull()) return false;
37+
if (isFull()) {
38+
return false;
39+
}
3640

3741
buffer[putPointer.getAndIncrement()] = item;
3842
size.incrementAndGet();
@@ -49,7 +53,9 @@ private static class CircularPointer {
4953
}
5054

5155
public int getAndIncrement() {
52-
if (pointer == max) pointer = 0;
56+
if (pointer == max) {
57+
pointer = 0;
58+
}
5359
int tmp = pointer;
5460
pointer++;
5561
return tmp;

src/main/java/com/thealgorithms/datastructures/graphs/Kosaraju.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ public void findStronglyConnectedComponents(int v, List<List<Integer>> transpose
127127
private void dfs(int node, int[] vis, List<List<Integer>> list) {
128128
vis[node] = 1;
129129
for (Integer neighbour : list.get(node)) {
130-
if (vis[neighbour] == 0) dfs(neighbour, vis, list);
130+
if (vis[neighbour] == 0) {
131+
dfs(neighbour, vis, list);
132+
}
131133
}
132134
stack.push(node);
133135
}
@@ -136,7 +138,9 @@ private void dfs(int node, int[] vis, List<List<Integer>> list) {
136138
private void dfs2(int node, int[] vis, List<List<Integer>> list) {
137139
vis[node] = 1;
138140
for (Integer neighbour : list.get(node)) {
139-
if (vis[neighbour] == 0) dfs2(neighbour, vis, list);
141+
if (vis[neighbour] == 0) {
142+
dfs2(neighbour, vis, list);
143+
}
140144
}
141145
scc.add(node);
142146
}

src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public List<List<Integer>> stronglyConnectedComponents(int v, List<List<Integer>
8282
Stack<Integer> st = new Stack<Integer>();
8383

8484
for (int i = 0; i < v; i++) {
85-
if (insertionTime[i] == -1) stronglyConnCompsUtil(i, lowTime, insertionTime, isInStack, st, graph);
85+
if (insertionTime[i] == -1) {
86+
stronglyConnCompsUtil(i, lowTime, insertionTime, isInStack, st, graph);
87+
}
8688
}
8789

8890
return sccList;

src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMap.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ private Node findEnd(Node n) {
6868
public Node findKey(int key) {
6969
if (!isEmpty()) {
7070
Node temp = first;
71-
if (temp.getKey() == key) return temp;
71+
if (temp.getKey() == key) {
72+
return temp;
73+
}
7274

7375
while ((temp = temp.getNext()) != null) {
74-
if (temp.getKey() == key) return temp;
76+
if (temp.getKey() == key) {
77+
return temp;
78+
}
7579
}
7680
}
7781
return null;

src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMapCuckooHashing.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,14 @@ public int findKeyInTable(int key) {
188188
throw new IllegalArgumentException("Table is empty");
189189
}
190190

191-
if (Objects.equals(buckets[hash], wrappedInt)) return hash;
191+
if (Objects.equals(buckets[hash], wrappedInt)) {
192+
return hash;
193+
}
192194

193195
hash = hashFunction2(key);
194-
if (!Objects.equals(buckets[hash], wrappedInt))
196+
if (!Objects.equals(buckets[hash], wrappedInt)) {
195197
throw new IllegalArgumentException("Key " + key + " not found in table");
196-
else {
198+
} else {
197199
return hash;
198200
}
199201
}

src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Main.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,30 @@ public static void main(String[] args) {
2323
choice = scan.nextInt();
2424

2525
switch (choice) {
26-
case 1: {
26+
case 1:
2727
System.out.println("Enter the Key: ");
2828
key = scan.nextInt();
2929
h.insertHash(key);
3030
break;
31-
}
32-
case 2: {
31+
32+
case 2:
3333
System.out.println("Enter the Key delete: ");
3434
key = scan.nextInt();
3535
h.deleteHash(key);
3636
break;
37-
}
38-
case 3: {
37+
38+
case 3:
3939
System.out.println("Print table");
4040
h.displayHashtable();
4141
break;
42-
}
43-
case 4: {
42+
43+
case 4:
4444
scan.close();
4545
return;
46-
}
47-
default: {
46+
47+
default:
4848
throw new IllegalArgumentException("Unexpected value: " + choice);
4949
}
50-
}
5150
}
5251
}
5352
}

src/main/java/com/thealgorithms/datastructures/hashmap/hashing/MainCuckooHashing.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,44 @@ public static void main(String[] args) {
2727
choice = scan.nextInt();
2828

2929
switch (choice) {
30-
case 1: {
30+
case 1:
3131
System.out.println("Enter the Key: ");
3232
key = scan.nextInt();
3333
h.insertKey2HashTable(key);
3434
break;
35-
}
36-
case 2: {
35+
36+
case 2:
3737
System.out.println("Enter the Key delete: ");
3838
key = scan.nextInt();
3939
h.deleteKeyFromHashTable(key);
4040
break;
41-
}
42-
case 3: {
41+
42+
case 3:
4343
System.out.println("Print table:\n");
4444
h.displayHashtable();
4545
break;
46-
}
47-
case 4: {
46+
47+
case 4:
4848
scan.close();
4949
return;
50-
}
51-
case 5: {
50+
51+
case 5:
5252
System.out.println("Enter the Key to find and print: ");
5353
key = scan.nextInt();
5454
System.out.println("Key: " + key + " is at index: " + h.findKeyInTable(key) + "\n");
5555
break;
56-
}
57-
case 6: {
56+
57+
case 6:
5858
System.out.printf("Load factor is: %.2f%n", h.checkLoadFactor());
5959
break;
60-
}
61-
case 7: {
60+
61+
case 7:
6262
h.reHashTableIncreasesTableSize();
6363
break;
64-
}
65-
default: {
64+
65+
default:
6666
throw new IllegalArgumentException("Unexpected value: " + choice);
6767
}
68-
}
6968
}
7069
}
7170
}

src/main/java/com/thealgorithms/datastructures/heaps/FibonacciHeap.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ private void updateMin(HeapNode posMin) {
231231
private void cascadingCuts(HeapNode curr) {
232232
if (!curr.isMarked()) { // stop the recursion
233233
curr.mark();
234-
if (!curr.isRoot()) this.markedHeapNoodesCounter++;
234+
if (!curr.isRoot()) {
235+
this.markedHeapNoodesCounter++;
236+
}
235237
} else {
236238
if (curr.isRoot()) {
237239
return;

src/main/java/com/thealgorithms/datastructures/heaps/LeftistHeap.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ public void merge(LeftistHeap h1) {
5656

5757
// Function merge with two Nodes a and b
5858
public Node merge(Node a, Node b) {
59-
if (a == null) return b;
59+
if (a == null) {
60+
return b;
61+
}
6062

61-
if (b == null) return a;
63+
if (b == null) {
64+
return a;
65+
}
6266

6367
// Violates leftist property, so must do a swap
6468
if (a.element > b.element) {
@@ -93,7 +97,9 @@ public void insert(int a) {
9397
// Returns and removes the minimum element in the heap
9498
public int extractMin() {
9599
// If is empty return -1
96-
if (isEmpty()) return -1;
100+
if (isEmpty()) {
101+
return -1;
102+
}
97103

98104
int min = root.element;
99105
root = merge(root.left, root.right);
@@ -109,7 +115,9 @@ public ArrayList<Integer> inOrder() {
109115

110116
// Auxiliary function for in_order
111117
private void inOrderAux(Node n, ArrayList<Integer> lst) {
112-
if (n == null) return;
118+
if (n == null) {
119+
return;
120+
}
113121
inOrderAux(n.left, lst);
114122
lst.add(n.element);
115123
inOrderAux(n.right, lst);

src/main/java/com/thealgorithms/datastructures/heaps/MaxHeap.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ public final void insertElement(HeapElement element) {
9898

9999
@Override
100100
public void deleteElement(int elementIndex) {
101-
if (maxHeap.isEmpty()) try {
101+
if (maxHeap.isEmpty()) {
102+
try {
102103
throw new EmptyHeapException("Attempt to delete an element from an empty heap");
103104
} catch (EmptyHeapException e) {
104105
e.printStackTrace();
105106
}
107+
}
106108
if ((elementIndex > maxHeap.size()) || (elementIndex <= 0)) {
107109
throw new IndexOutOfBoundsException("Index out of heap range");
108110
}

src/main/java/com/thealgorithms/datastructures/heaps/MinHeap.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ public final void insertElement(HeapElement element) {
9292

9393
@Override
9494
public void deleteElement(int elementIndex) {
95-
if (minHeap.isEmpty()) try {
95+
if (minHeap.isEmpty()) {
96+
try {
9697
throw new EmptyHeapException("Attempt to delete an element from an empty heap");
9798
} catch (EmptyHeapException e) {
9899
e.printStackTrace();
99100
}
101+
}
100102
if ((elementIndex > minHeap.size()) || (elementIndex <= 0)) {
101103
throw new IndexOutOfBoundsException("Index out of heap range");
102104
}

0 commit comments

Comments
 (0)