Skip to content

Commit 1dc3886

Browse files
Refactor Code Style (TheAlgorithms#4151)
1 parent 1ce9076 commit 1dc3886

File tree

100 files changed

+293
-319
lines changed

Some content is hidden

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

100 files changed

+293
-319
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private void storeAllPathsUtil(Integer u, Integer d, boolean[] isVisited, List<I
9191
}
9292

9393
// Driver program
94-
public static List<List<Integer>> allPathsFromSourceToTarget(int vertices, int a[][], int source, int destination)
94+
public static List<List<Integer>> allPathsFromSourceToTarget(int vertices, int[][] a, int source, int destination)
9595
{
9696
// Create a sample graph
9797
AllPathsFromSourceToTarget g = new AllPathsFromSourceToTarget(vertices);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class Blowfish {
1212

1313
//Initializing substitution boxes
14-
String S[][] = {
14+
String[][] S = {
1515
{
1616
"d1310ba6",
1717
"98dfb5ac",
@@ -1047,7 +1047,7 @@ public class Blowfish {
10471047
};
10481048

10491049
//Initializing subkeys with digits of pi
1050-
String P[] = {
1050+
String[] P = {
10511051
"243f6a88",
10521052
"85a308d3",
10531053
"13198a2e",
@@ -1146,7 +1146,7 @@ private String addBin(String a, String b) {
11461146
The outputs are added modulo 232 and XORed to produce the final 32-bit output
11471147
*/
11481148
private String f(String plainText) {
1149-
String a[] = new String[4];
1149+
String[] a = new String[4];
11501150
String ans = "";
11511151
for (int i = 0; i < 8; i += 2) {
11521152
//column number for S-box is a 8-bit value

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void encrypt(String message) {
2222
System.out.println("Enter key matrix size");
2323
int matrixSize = userInput.nextInt();
2424
System.out.println("Enter Key/encryptionKey matrix ");
25-
int keyMatrix[][] = new int[matrixSize][matrixSize];
25+
int[][] keyMatrix = new int[matrixSize][matrixSize];
2626
for (int i = 0; i < matrixSize; i++) {
2727
for (int j = 0; j < matrixSize; j++) {
2828
keyMatrix[i][j] = userInput.nextInt();
@@ -33,7 +33,7 @@ static void encrypt(String message) {
3333

3434
int[][] messageVector = new int[matrixSize][1];
3535
String CipherText = "";
36-
int cipherMatrix[][] = new int[matrixSize][1];
36+
int[][] cipherMatrix = new int[matrixSize][1];
3737
int j = 0;
3838
while (j < message.length()) {
3939
for (int i = 0; i < matrixSize; i++) {
@@ -69,7 +69,7 @@ static void decrypt(String message) {
6969
System.out.println("Enter key matrix size");
7070
int n = userInput.nextInt();
7171
System.out.println("Enter inverseKey/decryptionKey matrix ");
72-
int keyMatrix[][] = new int[n][n];
72+
int[][] keyMatrix = new int[n][n];
7373
for (int i = 0; i < n; i++) {
7474
for (int j = 0; j < n; j++) {
7575
keyMatrix[i][j] = userInput.nextInt();
@@ -81,7 +81,7 @@ static void decrypt(String message) {
8181
//solving for the required plaintext message
8282
int[][] messageVector = new int[n][1];
8383
String PlainText = "";
84-
int plainMatrix[][] = new int[n][1];
84+
int[][] plainMatrix = new int[n][1];
8585
int j = 0;
8686
while (j < message.length()) {
8787
for (int i = 0; i < n; i++) {
@@ -111,13 +111,13 @@ static void decrypt(String message) {
111111
}
112112

113113
// Determinant calculator
114-
public static int determinant(int a[][], int n) {
114+
public static int determinant(int[][] a, int n) {
115115
int det = 0, sign = 1, p = 0, q = 0;
116116

117117
if (n == 1) {
118118
det = a[0][0];
119119
} else {
120-
int b[][] = new int[n - 1][n - 1];
120+
int[][] b = new int[n - 1][n - 1];
121121
for (int x = 0; x < n; x++) {
122122
p = 0;
123123
q = 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ProductCipher {
66

7-
public static void main(String args[]) {
7+
public static void main(String[] args) {
88
Scanner sc = new Scanner(System.in);
99
System.out.println("Enter the input to be encrypted: ");
1010
String substitutionInput = sc.nextLine();

src/main/java/com/thealgorithms/conversions/BinaryToDecimal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static long binaryToDecimal(long binNum) {
2323
*
2424
* @param args Command line arguments
2525
*/
26-
public static void main(String args[]) {
26+
public static void main(String[] args) {
2727
Scanner sc = new Scanner(System.in);
2828
System.out.print("Binary number: ");
2929
System.out.println("Decimal equivalent:" + binaryToDecimal(sc.nextLong()));

src/main/java/com/thealgorithms/conversions/BinaryToOctal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class BinaryToOctal {
1414
*
1515
* @param args Command line arguments
1616
*/
17-
public static void main(String args[]) {
17+
public static void main(String[] args) {
1818
Scanner sc = new Scanner(System.in);
1919
System.out.println("Input the binary number: ");
2020
int b = sc.nextInt();

src/main/java/com/thealgorithms/conversions/DecimalToBinary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DecimalToBinary {
1212
*
1313
* @param args Command Line Arguments
1414
*/
15-
public static void main(String args[]) {
15+
public static void main(String[] args) {
1616
conventionalConversion();
1717
bitwiseConversion();
1818
}

src/main/java/com/thealgorithms/conversions/HexToOct.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static int decimal2octal(int q) {
5252
*
5353
* @param args arguments
5454
*/
55-
public static void main(String args[]) {
55+
public static void main(String[] args) {
5656
String hexadecnum;
5757
int decnum, octalnum;
5858
Scanner scan = new Scanner(System.in);

src/main/java/com/thealgorithms/conversions/HexaDecimalToDecimal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static int getHexaToDec(String hex) {
1717
}
1818

1919
// Main method gets the hexadecimal input from user and converts it into Decimal output.
20-
public static void main(String args[]) {
20+
public static void main(String[] args) {
2121
String hexa_Input;
2222
int dec_output;
2323
Scanner scan = new Scanner(System.in);

src/main/java/com/thealgorithms/conversions/OctalToDecimal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class OctalToDecimal {
1414
*
1515
* @param args Command line arguments
1616
*/
17-
public static void main(String args[]) {
17+
public static void main(String[] args) {
1818
Scanner sc = new Scanner(System.in);
1919
System.out.print("Octal Input: ");
2020
String inputOctal = sc.nextLine();

src/main/java/com/thealgorithms/conversions/OctalToHexadecimal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static String decimalToHex(int d) {
4646
return hex;
4747
}
4848

49-
public static void main(String args[]) {
49+
public static void main(String[] args) {
5050
Scanner input = new Scanner(System.in);
5151
System.out.print("Enter the Octal number: ");
5252
// Take octal number as input from user in a string

src/main/java/com/thealgorithms/conversions/TurkishToLatinConversion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class TurkishToLatinConversion {
1414
*
1515
* @param args Command line arguments
1616
*/
17-
public static void main(String args[]) {
17+
public static void main(String[] args) {
1818
Scanner sc = new Scanner(System.in);
1919
System.out.println("Input the string: ");
2020
String b = sc.next();

src/main/java/com/thealgorithms/datastructures/bags/Bag.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ public void add(Element element) {
5959
* @return true if bag contains element, otherwise false
6060
*/
6161
public boolean contains(Element element) {
62-
Iterator<Element> iterator = this.iterator();
63-
while (iterator.hasNext()) {
64-
if (iterator.next().equals(element)) {
62+
for (Element value : this) {
63+
if (value.equals(element)) {
6564
return true;
6665
}
6766
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class BellmanFord /*Implementation of Bellman ford to detect negative cycles. Gr
66
start vertex, end vertex and weights. Vertices should be labelled with a number between 0 and total number of vertices-1,both inclusive*/{
77

88
int vertex, edge;
9-
private Edge edges[];
9+
private Edge[] edges;
1010
private int index = 0;
1111

1212
BellmanFord(int v, int e) {
@@ -36,15 +36,15 @@ public Edge(int a, int b, int c) {
3636
* @param p[] Parent array which shows updates in edges
3737
* @param i Current vertex under consideration
3838
*/
39-
void printPath(int p[], int i) {
39+
void printPath(int[] p, int i) {
4040
if (p[i] == -1) { // Found the path back to parent
4141
return;
4242
}
4343
printPath(p, p[i]);
4444
System.out.print(i + " ");
4545
}
4646

47-
public static void main(String args[]) {
47+
public static void main(String[] args) {
4848
BellmanFord obj = new BellmanFord(0, 0); // Dummy object to call nonstatic variables
4949
obj.go();
5050
}
@@ -55,17 +55,17 @@ public void go() { // shows distance to all vertices // Interactive run for unde
5555
System.out.println("Enter no. of vertices and edges please");
5656
v = sc.nextInt();
5757
e = sc.nextInt();
58-
Edge arr[] = new Edge[e]; // Array of edges
58+
Edge[] arr = new Edge[e]; // Array of edges
5959
System.out.println("Input edges");
6060
for (i = 0; i < e; i++) {
6161
u = sc.nextInt();
6262
ve = sc.nextInt();
6363
w = sc.nextInt();
6464
arr[i] = new Edge(u, ve, w);
6565
}
66-
int dist[] = new int[v]; // Distance array for holding the finalized shortest path distance between source
66+
int[] dist = new int[v]; // Distance array for holding the finalized shortest path distance between source
6767
// and all vertices
68-
int p[] = new int[v]; // Parent array for holding the paths
68+
int[] p = new int[v]; // Parent array for holding the paths
6969
for (i = 0; i < v; i++) {
7070
dist[i] = Integer.MAX_VALUE; // Initializing distance values
7171
}
@@ -113,11 +113,11 @@ public void go() { // shows distance to all vertices // Interactive run for unde
113113
* @param end Ending vertex
114114
* @param Edge Array of edges
115115
*/
116-
public void show(int source, int end, Edge arr[]) { // be created by using addEdge() method and passed by calling getEdgeArray() method // Just shows results of computation, if graph is passed to it. The graph should
116+
public void show(int source, int end, Edge[] arr) { // be created by using addEdge() method and passed by calling getEdgeArray() method // Just shows results of computation, if graph is passed to it. The graph should
117117
int i, j, v = vertex, e = edge, neg = 0;
118-
double dist[] = new double[v]; // Distance array for holding the finalized shortest path distance between source
118+
double[] dist = new double[v]; // Distance array for holding the finalized shortest path distance between source
119119
// and all vertices
120-
int p[] = new int[v]; // Parent array for holding the paths
120+
int[] p = new int[v]; // Parent array for holding the paths
121121
for (i = 0; i < v; i++) {
122122
dist[i] = Integer.MAX_VALUE; // Initializing distance values
123123
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class dijkstras {
88

99
int k = 9;
1010

11-
int minDist(int dist[], Boolean Set[]) {
11+
int minDist(int[] dist, Boolean[] Set) {
1212
int min = Integer.MAX_VALUE, min_index = -1;
1313

1414
for (int r = 0; r < k; r++) {
@@ -21,16 +21,16 @@ int minDist(int dist[], Boolean Set[]) {
2121
return min_index;
2222
}
2323

24-
void print(int dist[]) {
24+
void print(int[] dist) {
2525
System.out.println("Vertex \t\t Distance");
2626
for (int i = 0; i < k; i++) {
2727
System.out.println(i + " \t " + dist[i]);
2828
}
2929
}
3030

31-
void dijkstra(int graph[][], int src) {
32-
int dist[] = new int[k];
33-
Boolean Set[] = new Boolean[k];
31+
void dijkstra(int[][] graph, int src) {
32+
int[] dist = new int[k];
33+
Boolean[] Set = new Boolean[k];
3434

3535
for (int i = 0; i < k; i++) {
3636
dist[i] = Integer.MAX_VALUE;
@@ -60,7 +60,7 @@ void dijkstra(int graph[][], int src) {
6060
}
6161

6262
public static void main(String[] args) {
63-
int graph[][] = new int[][] {
63+
int[][] graph = new int[][] {
6464
{ 0, 4, 0, 0, 0, 0, 0, 8, 0 },
6565
{ 4, 0, 8, 0, 0, 0, 0, 11, 0 },
6666
{ 0, 8, 0, 7, 0, 4, 0, 0, 2 },

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public class FloydWarshall {
66

7-
private int DistanceMatrix[][];
7+
private int[][] DistanceMatrix;
88
private int numberofvertices; // number of vertices in the graph
99
public static final int INFINITY = 999;
1010

@@ -15,7 +15,7 @@ public FloydWarshall(int numberofvertices) {
1515
this.numberofvertices = numberofvertices;
1616
}
1717

18-
public void floydwarshall(int AdjacencyMatrix[][]) { // calculates all the distances from source to destination vertex
18+
public void floydwarshall(int[][] AdjacencyMatrix) { // calculates all the distances from source to destination vertex
1919
for (int source = 1; source <= numberofvertices; source++) {
2020
for (
2121
int destination = 1;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public String toString() {
122122

123123
public class Graphs {
124124

125-
public static void main(String args[]) {
125+
public static void main(String[] args) {
126126
AdjacencyListGraph<Integer> graph = new AdjacencyListGraph<>();
127127
assert graph.addEdge(1, 2);
128128
assert graph.addEdge(1, 5);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public List<List<Integer>> kosaraju(int v, List<List<Integer>> list){
8383
}
8484

8585
private void sortEdgesByLowestFinishTime(int v, List<List<Integer>> list){
86-
int vis[] = new int[v];
86+
int[] vis = new int[v];
8787
for (int i = 0; i < v; i++) {
8888
if(vis[i] == 0){
8989
dfs(i, vis, list);
@@ -110,7 +110,7 @@ private List<List<Integer>> createTransposeMatrix(int v, List<List<Integer>> lis
110110
* @param transposeGraph Transpose of the given adjacency list
111111
*/
112112
public void findStronglyConnectedComponents(int v, List<List<Integer>> transposeGraph){
113-
int vis[] = new int[v];
113+
int[] vis = new int[v];
114114
while (!stack.isEmpty()) {
115115
var node = stack.pop();
116116
if(vis[node] == 0){
@@ -122,7 +122,7 @@ public void findStronglyConnectedComponents(int v, List<List<Integer>> transpose
122122
}
123123

124124
//Dfs to store the nodes in order of lowest finish time
125-
private void dfs(int node, int vis[], List<List<Integer>> list){
125+
private void dfs(int node, int[] vis, List<List<Integer>> list){
126126
vis[node] = 1;
127127
for(Integer neighbour : list.get(node)){
128128
if(vis[neighbour] == 0)
@@ -132,7 +132,7 @@ private void dfs(int node, int vis[], List<List<Integer>> list){
132132
}
133133

134134
//Dfs to find all the nodes of each strongly connected component
135-
private void dfs2(int node, int vis[], List<List<Integer>> list){
135+
private void dfs2(int node, int[] vis, List<List<Integer>> list){
136136
vis[node] = 1;
137137
for(Integer neighbour : list.get(node)){
138138
if(vis[neighbour] == 0)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
public class MatrixGraphs {
1616

17-
public static void main(String args[]) {
17+
public static void main(String[] args) {
1818
AdjacencyMatrixGraph graph = new AdjacencyMatrixGraph(10);
1919
graph.addEdge(1, 2);
2020
graph.addEdge(1, 5);

0 commit comments

Comments
 (0)