Skip to content

Commit 00282ef

Browse files
authored
style: format code (TheAlgorithms#4212)
close TheAlgorithms#4204
1 parent ad03086 commit 00282ef

File tree

521 files changed

+5269
-7345
lines changed

Some content is hidden

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

521 files changed

+5269
-7345
lines changed

src/main/java/com/thealgorithms/audiofilters/IIRFilter.java

+6-14
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public class IIRFilter {
2222
*/
2323
public IIRFilter(int order) throws IllegalArgumentException {
2424
if (order < 1) {
25-
throw new IllegalArgumentException(
26-
"order must be greater than zero"
27-
);
25+
throw new IllegalArgumentException("order must be greater than zero");
2826
}
2927

3028
this.order = order;
@@ -47,24 +45,19 @@ public IIRFilter(int order) throws IllegalArgumentException {
4745
* @throws IllegalArgumentException if {@code aCoeffs} or {@code bCoeffs} is
4846
* not of size {@code order}, or if {@code aCoeffs[0]} is 0.0
4947
*/
50-
public void setCoeffs(double[] aCoeffs, double[] bCoeffs)
51-
throws IllegalArgumentException {
48+
public void setCoeffs(double[] aCoeffs, double[] bCoeffs) throws IllegalArgumentException {
5249
if (aCoeffs.length != order) {
5350
throw new IllegalArgumentException(
54-
"aCoeffs must be of size " + order + ", got " + aCoeffs.length
55-
);
51+
"aCoeffs must be of size " + order + ", got " + aCoeffs.length);
5652
}
5753

5854
if (aCoeffs[0] == 0.0) {
59-
throw new IllegalArgumentException(
60-
"aCoeffs.get(0) must not be zero"
61-
);
55+
throw new IllegalArgumentException("aCoeffs.get(0) must not be zero");
6256
}
6357

6458
if (bCoeffs.length != order) {
6559
throw new IllegalArgumentException(
66-
"bCoeffs must be of size " + order + ", got " + bCoeffs.length
67-
);
60+
"bCoeffs must be of size " + order + ", got " + bCoeffs.length);
6861
}
6962

7063
for (int i = 0; i <= order; i++) {
@@ -84,8 +77,7 @@ public double process(double sample) {
8477

8578
// Process
8679
for (int i = 1; i <= order; i++) {
87-
result +=
88-
(coeffsB[i] * historyX[i - 1] - coeffsA[i] * historyY[i - 1]);
80+
result += (coeffsB[i] * historyX[i - 1] - coeffsA[i] * historyY[i - 1]);
8981
}
9082
result = (result + coeffsB[0] * sample) / coeffsA[0];
9183

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

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/** Author : Siddhant Swarup Mallick
1+
/**
2+
* Author : Siddhant Swarup Mallick
23
* Github : https://github.com/siddhant2002
34
*/
45

@@ -15,13 +16,12 @@ public class AllPathsFromSourceToTarget {
1516
private int v;
1617

1718
// To store the paths from source to destination
18-
static List<List<Integer>> nm=new ArrayList<>();
19+
static List<List<Integer>> nm = new ArrayList<>();
1920
// adjacency list
2021
private ArrayList<Integer>[] adjList;
2122

2223
// Constructor
23-
public AllPathsFromSourceToTarget(int vertices)
24-
{
24+
public AllPathsFromSourceToTarget(int vertices) {
2525

2626
// initialise vertex count
2727
this.v = vertices;
@@ -31,8 +31,7 @@ public AllPathsFromSourceToTarget(int vertices)
3131
}
3232

3333
// utility method to initialise adjacency list
34-
private void initAdjList()
35-
{
34+
private void initAdjList() {
3635
adjList = new ArrayList[v];
3736

3837
for (int i = 0; i < v; i++) {
@@ -41,15 +40,12 @@ private void initAdjList()
4140
}
4241

4342
// add edge from u to v
44-
public void addEdge(int u, int v)
45-
{
43+
public void addEdge(int u, int v) {
4644
// Add v to u's list.
4745
adjList[u].add(v);
4846
}
4947

50-
51-
public void storeAllPaths(int s, int d)
52-
{
48+
public void storeAllPaths(int s, int d) {
5349
boolean[] isVisited = new boolean[v];
5450
ArrayList<Integer> pathList = new ArrayList<>();
5551

@@ -61,9 +57,9 @@ public void storeAllPaths(int s, int d)
6157

6258
// A recursive function to print all paths from 'u' to 'd'.
6359
// isVisited[] keeps track of vertices in current path.
64-
// localPathList<> stores actual vertices in the current path
65-
private void storeAllPathsUtil(Integer u, Integer d, boolean[] isVisited, List<Integer> localPathList)
66-
{
60+
// localPathList<> stores actual vertices in the current path
61+
private void storeAllPathsUtil(
62+
Integer u, Integer d, boolean[] isVisited, List<Integer> localPathList) {
6763

6864
if (u.equals(d)) {
6965
nm.add(new ArrayList<>(localPathList));
@@ -74,7 +70,7 @@ private void storeAllPathsUtil(Integer u, Integer d, boolean[] isVisited, List<I
7470
isVisited[u] = true;
7571

7672
// Recursion for all the vertices adjacent to current vertex
77-
73+
7874
for (Integer i : adjList[u]) {
7975
if (!isVisited[i]) {
8076
// store current node in path[]
@@ -91,12 +87,11 @@ private void storeAllPathsUtil(Integer u, Integer d, boolean[] isVisited, List<I
9187
}
9288

9389
// Driver program
94-
public static List<List<Integer>> allPathsFromSourceToTarget(int vertices, int[][] a, int source, int destination)
95-
{
90+
public static List<List<Integer>> allPathsFromSourceToTarget(
91+
int vertices, int[][] a, int source, int destination) {
9692
// Create a sample graph
9793
AllPathsFromSourceToTarget g = new AllPathsFromSourceToTarget(vertices);
98-
for(int i=0 ; i<a.length ; i++)
99-
{
94+
for (int i = 0; i < a.length; i++) {
10095
g.addEdge(a[i][0], a[i][1]);
10196
// edges are added
10297
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static List<TreeSet<Integer>> combination(int n, int k) {
2222
length = k;
2323
Integer[] arr = new Integer[n];
2424
for (int i = 1; i <= n; i++) {
25-
arr[i-1] = i;
25+
arr[i - 1] = i;
2626
}
2727
return Combination.combination(arr, length);
2828
}

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ public static <T> List<TreeSet<T>> combination(T[] arr, int n) {
3838
* @param <T> the type of elements in the array.
3939
*/
4040
private static <T> void backtracking(
41-
T[] arr,
42-
int index,
43-
TreeSet<T> currSet,
44-
List<TreeSet<T>> result
45-
) {
41+
T[] arr, int index, TreeSet<T> currSet, List<TreeSet<T>> result) {
4642
if (index + length - currSet.size() > arr.length) return;
4743
if (length - 1 == currSet.size()) {
4844
for (int i = index; i < arr.length; i++) {

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ public static void putPixel(int[][] image, int x, int y, int newColor) {
3838
* @param newColor The new color which to be filled in the image
3939
* @param oldColor The old color which is to be replaced in the image
4040
*/
41-
public static void floodFill(
42-
int[][] image,
43-
int x,
44-
int y,
45-
int newColor,
46-
int oldColor
47-
) {
41+
public static void floodFill(int[][] image, int x, int y, int newColor, int oldColor) {
4842
if (x < 0 || x >= image.length) return;
4943
if (y < 0 || y >= image[x].length) return;
5044
if (getPixel(image, x, y) != oldColor) return;

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

+18-23
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
/*
66
* Problem Statement: -
7-
8-
Given a N*N board with the Knight placed on the first block of an empty board. Moving according to the rules of
9-
chess knight must visit each square exactly once. Print the order of each cell in which they are visited.
7+
8+
Given a N*N board with the Knight placed on the first block of an empty board. Moving according
9+
to the rules of chess knight must visit each square exactly once. Print the order of each cell in
10+
which they are visited.
1011
1112
Example: -
1213
@@ -27,14 +28,14 @@ public class KnightsTour {
2728

2829
private static final int base = 12;
2930
private static final int[][] moves = {
30-
{ 1, -2 },
31-
{ 2, -1 },
32-
{ 2, 1 },
33-
{ 1, 2 },
34-
{ -1, 2 },
35-
{ -2, 1 },
36-
{ -2, -1 },
37-
{ -1, -2 },
31+
{1, -2},
32+
{2, -1},
33+
{2, 1},
34+
{1, 2},
35+
{-1, 2},
36+
{-2, 1},
37+
{-2, -1},
38+
{-1, -2},
3839
}; // Possible moves by knight on chess
3940
private static int[][] grid; // chess grid
4041
private static int total; // total squares in chess
@@ -75,23 +76,17 @@ private static boolean solve(int row, int column, int count) {
7576
return false;
7677
}
7778

78-
Collections.sort(
79-
neighbor,
80-
new Comparator<int[]>() {
81-
public int compare(int[] a, int[] b) {
82-
return a[2] - b[2];
83-
}
79+
Collections.sort(neighbor, new Comparator<int[]>() {
80+
public int compare(int[] a, int[] b) {
81+
return a[2] - b[2];
8482
}
85-
);
83+
});
8684

8785
for (int[] nb : neighbor) {
8886
row = nb[0];
8987
column = nb[1];
9088
grid[row][column] = count;
91-
if (
92-
!orphanDetected(count, row, column) &&
93-
solve(row, column, count + 1)
94-
) {
89+
if (!orphanDetected(count, row, column) && solve(row, column, count + 1)) {
9590
return true;
9691
}
9792
grid[row][column] = 0;
@@ -109,7 +104,7 @@ private static List<int[]> neighbors(int row, int column) {
109104
int y = m[1];
110105
if (grid[row + y][column + x] == 0) {
111106
int num = countNeighbors(row + y, column + x);
112-
neighbour.add(new int[] { row + y, column + x, num });
107+
neighbour.add(new int[] {row + y, column + x, num});
113108
}
114109
}
115110
return neighbour;

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

+7-9
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public static void mazeRecursion() {
5151
setWay2(map2, 1, 1);
5252

5353
// Print out the new map1, with the ball footprint
54-
System.out.println(
55-
"After the ball goes through the map1,show the current map1 condition"
56-
);
54+
System.out.println("After the ball goes through the map1,show the current map1 condition");
5755
for (int i = 0; i < 8; i++) {
5856
for (int j = 0; j < 7; j++) {
5957
System.out.print(map[i][j] + " ");
@@ -62,9 +60,7 @@ public static void mazeRecursion() {
6260
}
6361

6462
// Print out the new map2, with the ball footprint
65-
System.out.println(
66-
"After the ball goes through the map2,show the current map2 condition"
67-
);
63+
System.out.println("After the ball goes through the map2,show the current map2 condition");
6864
for (int i = 0; i < 8; i++) {
6965
for (int j = 0; j < 7; j++) {
7066
System.out.print(map2[i][j] + " ");
@@ -85,7 +81,7 @@ public static void mazeRecursion() {
8581
* means the ball has gone through the path but this path is dead end
8682
* 5. We will need strategy for the ball to pass through the maze for example:
8783
* Down -> Right -> Up -> Left, if the path doesn't work, then backtrack
88-
*
84+
*
8985
* @author OngLipWei
9086
* @version Jun 23, 2021 11:36:14 AM
9187
* @param map The maze
@@ -99,7 +95,8 @@ public static boolean setWay(int[][] map, int i, int j) {
9995
}
10096
if (map[i][j] == 0) { // if the ball haven't gone through this point
10197
// then the ball follows the move strategy : down -> right -> up -> left
102-
map[i][j] = 2; // we assume that this path is feasible first, set the current point to 2 first。
98+
map[i][j] = 2; // we assume that this path is feasible first, set the current point to 2
99+
// first。
103100
if (setWay(map, i + 1, j)) { // go down
104101
return true;
105102
} else if (setWay(map, i, j + 1)) { // go right
@@ -129,7 +126,8 @@ public static boolean setWay2(int[][] map, int i, int j) {
129126
}
130127
if (map[i][j] == 0) { // if the ball haven't gone through this point
131128
// then the ball follows the move strategy : up->right->down->left
132-
map[i][j] = 2; // we assume that this path is feasible first, set the current point to 2 first。
129+
map[i][j] = 2; // we assume that this path is feasible first, set the current point to 2
130+
// first。
133131
if (setWay2(map, i - 1, j)) { // go up
134132
return true;
135133
} else if (setWay2(map, i, j + 1)) { // go right

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

+6-19
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,8 @@ public static void placeQueens(final int queens) {
4747
List<List<String>> arrangements = new ArrayList<List<String>>();
4848
getSolution(queens, arrangements, new int[queens], 0);
4949
if (arrangements.isEmpty()) {
50-
System.out.println(
51-
"There is no way to place " +
52-
queens +
53-
" queens on board of size " +
54-
queens +
55-
"x" +
56-
queens
57-
);
50+
System.out.println("There is no way to place " + queens + " queens on board of size "
51+
+ queens + "x" + queens);
5852
} else {
5953
System.out.println("Arrangement for placing " + queens + " queens");
6054
}
@@ -73,11 +67,7 @@ public static void placeQueens(final int queens) {
7367
* @param columnIndex: This is the column in which queen is being placed
7468
*/
7569
private static void getSolution(
76-
int boardSize,
77-
List<List<String>> solutions,
78-
int[] columns,
79-
int columnIndex
80-
) {
70+
int boardSize, List<List<String>> solutions, int[] columns, int columnIndex) {
8171
if (columnIndex == boardSize) {
8272
// this means that all queens have been placed
8373
List<String> sol = new ArrayList<String>();
@@ -96,7 +86,8 @@ private static void getSolution(
9686
for (int rowIndex = 0; rowIndex < boardSize; rowIndex++) {
9787
columns[columnIndex] = rowIndex;
9888
if (isPlacedCorrectly(columns, rowIndex, columnIndex)) {
99-
// If queen is placed successfully at rowIndex in column=columnIndex then try placing queen in next column
89+
// If queen is placed successfully at rowIndex in column=columnIndex then try
90+
// placing queen in next column
10091
getSolution(boardSize, solutions, columns, columnIndex + 1);
10192
}
10293
}
@@ -111,11 +102,7 @@ private static void getSolution(
111102
* @param columnIndex: column in which queen is being placed
112103
* @return true: if queen can be placed safely false: otherwise
113104
*/
114-
private static boolean isPlacedCorrectly(
115-
int[] columns,
116-
int rowIndex,
117-
int columnIndex
118-
) {
105+
private static boolean isPlacedCorrectly(int[] columns, int rowIndex, int columnIndex) {
119106
for (int i = 0; i < columnIndex; i++) {
120107
int diff = Math.abs(columns[i] - rowIndex);
121108
if (diff == 0 || columnIndex - i == diff) {

0 commit comments

Comments
 (0)