mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-25 05:22:39 +08:00
style: enable MultipleVariableDeclarations
in checkstyle (#5175)
Co-authored-by: vaibhav <vaibhav.waghmare@techprescient.com>
This commit is contained in:
@ -11,7 +11,8 @@ class BellmanFord /*
|
||||
*/
|
||||
{
|
||||
|
||||
int vertex, edge;
|
||||
int vertex;
|
||||
int edge;
|
||||
private Edge[] edges;
|
||||
private int index = 0;
|
||||
|
||||
@ -23,7 +24,8 @@ class BellmanFord /*
|
||||
|
||||
class Edge {
|
||||
|
||||
int u, v;
|
||||
int u;
|
||||
int v;
|
||||
int w;
|
||||
|
||||
/**
|
||||
@ -58,7 +60,14 @@ class BellmanFord /*
|
||||
public void go() { // shows distance to all vertices // Interactive run for understanding the
|
||||
try ( // class first time. Assumes source vertex is 0 and
|
||||
Scanner sc = new Scanner(System.in)) {
|
||||
int i, v, e, u, ve, w, j, neg = 0;
|
||||
int i;
|
||||
int v;
|
||||
int e;
|
||||
int u;
|
||||
int ve;
|
||||
int w;
|
||||
int j;
|
||||
int neg = 0;
|
||||
System.out.println("Enter no. of vertices and edges please");
|
||||
v = sc.nextInt();
|
||||
e = sc.nextInt();
|
||||
@ -120,7 +129,11 @@ class BellmanFord /*
|
||||
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
|
||||
int i, j, v = vertex, e = edge, neg = 0;
|
||||
int i;
|
||||
int j;
|
||||
int v = vertex;
|
||||
int e = edge;
|
||||
int neg = 0;
|
||||
double[] dist = new double[v]; // Distance array for holding the finalized shortest path
|
||||
// distance between source
|
||||
// and all vertices
|
||||
|
@ -22,7 +22,8 @@ class Graph<E extends Comparable<E>> {
|
||||
|
||||
class Edge {
|
||||
|
||||
Node startNode, endNode;
|
||||
Node startNode;
|
||||
Node endNode;
|
||||
|
||||
Edge(Node startNode, Node endNode) {
|
||||
this.startNode = startNode;
|
||||
@ -46,7 +47,8 @@ class Graph<E extends Comparable<E>> {
|
||||
* @param endNode the ending Node from the edge
|
||||
*/
|
||||
public void addEdge(E startNode, E endNode) {
|
||||
Node start = null, end = null;
|
||||
Node start = null;
|
||||
Node end = null;
|
||||
for (Node node : nodeList) {
|
||||
if (startNode.compareTo(node.name) == 0) {
|
||||
start = node;
|
||||
|
@ -5,7 +5,8 @@ import java.util.Scanner;
|
||||
|
||||
class Cycle {
|
||||
|
||||
private int nodes, edges;
|
||||
private final int nodes;
|
||||
private final int edges;
|
||||
private int[][] adjacencyMatrix;
|
||||
private boolean[] visited;
|
||||
ArrayList<ArrayList<Integer>> cycles = new ArrayList<ArrayList<Integer>>();
|
||||
@ -27,7 +28,8 @@ class Cycle {
|
||||
System.out.println("Enter the details of each edges <Start Node> <End Node>");
|
||||
|
||||
for (int i = 0; i < edges; i++) {
|
||||
int start, end;
|
||||
int start;
|
||||
int end;
|
||||
start = in.nextInt();
|
||||
end = in.nextInt();
|
||||
adjacencyMatrix[start][end] = 1;
|
||||
|
@ -9,7 +9,8 @@ class dijkstras {
|
||||
int k = 9;
|
||||
|
||||
int minDist(int[] dist, Boolean[] Set) {
|
||||
int min = Integer.MAX_VALUE, min_index = -1;
|
||||
int min = Integer.MAX_VALUE;
|
||||
int min_index = -1;
|
||||
|
||||
for (int r = 0; r < k; r++) {
|
||||
if (!Set[r] && dist[r] <= min) {
|
||||
|
@ -75,7 +75,8 @@ class AdjacencyListGraph<E extends Comparable<E>> {
|
||||
* already did
|
||||
*/
|
||||
public boolean addEdge(E from, E to) {
|
||||
Vertex fromV = null, toV = null;
|
||||
Vertex fromV = null;
|
||||
Vertex toV = null;
|
||||
for (Vertex v : vertices) {
|
||||
if (from.compareTo(v.data) == 0) { // see if from vertex already exists
|
||||
fromV = v;
|
||||
|
@ -8,7 +8,8 @@ package com.thealgorithms.datastructures.graphs;
|
||||
*/
|
||||
public class HamiltonianCycle {
|
||||
|
||||
private int V, pathCount;
|
||||
private int V;
|
||||
private int pathCount;
|
||||
private int[] cycle;
|
||||
private int[][] graph;
|
||||
|
||||
|
@ -14,7 +14,8 @@ class PrimMST {
|
||||
// value, from the set of vertices not yet included in MST
|
||||
int minKey(int[] key, Boolean[] mstSet) {
|
||||
// Initialize min value
|
||||
int min = Integer.MAX_VALUE, min_index = -1;
|
||||
int min = Integer.MAX_VALUE;
|
||||
int min_index = -1;
|
||||
|
||||
for (int v = 0; v < V; v++) {
|
||||
if (!mstSet[v] && key[v] < min) {
|
||||
|
@ -66,8 +66,10 @@ public class HashMapCuckooHashing {
|
||||
*/
|
||||
|
||||
public void insertKey2HashTable(int key) {
|
||||
Integer wrappedInt = key, temp;
|
||||
int hash, loopCounter = 0;
|
||||
Integer wrappedInt = key;
|
||||
Integer temp;
|
||||
int hash;
|
||||
int loopCounter = 0;
|
||||
|
||||
if (isFull()) {
|
||||
System.out.println("Hash table is full, lengthening & rehashing table");
|
||||
|
@ -7,7 +7,8 @@ public final class Main {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int choice, key;
|
||||
int choice;
|
||||
int key;
|
||||
|
||||
HashMap h = new HashMap(7);
|
||||
Scanner In = new Scanner(System.in);
|
||||
|
@ -7,7 +7,8 @@ public final class MainCuckooHashing {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int choice, key;
|
||||
int choice;
|
||||
int key;
|
||||
|
||||
HashMapCuckooHashing h = new HashMapCuckooHashing(7);
|
||||
Scanner In = new Scanner(System.in);
|
||||
|
@ -13,9 +13,11 @@ import java.util.ArrayList;
|
||||
*/
|
||||
|
||||
public class LeftistHeap {
|
||||
private final class Node {
|
||||
private int element, npl;
|
||||
private Node left, right;
|
||||
private static final class Node {
|
||||
private final int element;
|
||||
private int npl;
|
||||
private Node left;
|
||||
private Node right;
|
||||
|
||||
// Node constructor setting the data element and left/right pointers to null
|
||||
private Node(int element) {
|
||||
|
@ -82,13 +82,15 @@ public class SinglyLinkedList implements Iterable<Integer> {
|
||||
if (valueFirst == valueSecond) {
|
||||
return;
|
||||
}
|
||||
Node previousA = null, currentA = head;
|
||||
Node previousA = null;
|
||||
Node currentA = head;
|
||||
while (currentA != null && currentA.value != valueFirst) {
|
||||
previousA = currentA;
|
||||
currentA = currentA.next;
|
||||
}
|
||||
|
||||
Node previousB = null, currentB = head;
|
||||
Node previousB = null;
|
||||
Node currentB = head;
|
||||
while (currentB != null && currentB.value != valueSecond) {
|
||||
previousB = currentB;
|
||||
currentB = currentB.next;
|
||||
|
@ -9,7 +9,9 @@ public class AVLTree {
|
||||
private int key;
|
||||
private int balance;
|
||||
private int height;
|
||||
private Node left, right, parent;
|
||||
private Node left;
|
||||
private Node right;
|
||||
private Node parent;
|
||||
|
||||
Node(int k, Node p) {
|
||||
key = k;
|
||||
|
@ -14,14 +14,16 @@ public final class LCA {
|
||||
ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
|
||||
|
||||
// v is the number of vertices and e is the number of edges
|
||||
int v = SCANNER.nextInt(), e = v - 1;
|
||||
int v = SCANNER.nextInt();
|
||||
int e = v - 1;
|
||||
|
||||
for (int i = 0; i < v; i++) {
|
||||
adj.add(new ArrayList<Integer>());
|
||||
}
|
||||
|
||||
// Storing the given tree as an adjacency list
|
||||
int to, from;
|
||||
int to;
|
||||
int from;
|
||||
for (int i = 0; i < e; i++) {
|
||||
to = SCANNER.nextInt();
|
||||
from = SCANNER.nextInt();
|
||||
@ -40,7 +42,8 @@ public final class LCA {
|
||||
dfs(adj, 0, -1, parent, depth);
|
||||
|
||||
// Inputting the two vertices whose LCA is to be calculated
|
||||
int v1 = SCANNER.nextInt(), v2 = SCANNER.nextInt();
|
||||
int v1 = SCANNER.nextInt();
|
||||
int v2 = SCANNER.nextInt();
|
||||
|
||||
// Outputting the LCA
|
||||
System.out.println(getLCA(v1, v2, depth, parent));
|
||||
|
@ -10,10 +10,12 @@ public class LazySegmentTree {
|
||||
*/
|
||||
static class Node {
|
||||
|
||||
private final int start, end; // start and end of the segment represented by this node
|
||||
private final int start;
|
||||
private final int end; // start and end of the segment represented by this node
|
||||
private int value; // value is the sum of all elements in the range [start, end)
|
||||
private int lazy; // lazied value that should be added to children nodes
|
||||
Node left, right; // left and right children
|
||||
Node left;
|
||||
Node right; // left and right children
|
||||
|
||||
Node(int start, int end, int value) {
|
||||
this.start = start;
|
||||
|
@ -10,7 +10,8 @@ class TreeNode {
|
||||
// Members
|
||||
|
||||
int key;
|
||||
TreeNode left, right;
|
||||
TreeNode left;
|
||||
TreeNode right;
|
||||
|
||||
// Constructor
|
||||
TreeNode(int key) {
|
||||
|
@ -12,8 +12,11 @@ public class RedBlackBST {
|
||||
|
||||
private class Node {
|
||||
|
||||
int key = -1, color = B;
|
||||
Node left = nil, right = nil, p = nil;
|
||||
int key = -1;
|
||||
int color = B;
|
||||
Node left = nil;
|
||||
Node right = nil;
|
||||
Node p = nil;
|
||||
|
||||
Node(int key) {
|
||||
this.key = key;
|
||||
|
@ -29,7 +29,8 @@ public class TreeRandomNode {
|
||||
private final class Node {
|
||||
|
||||
int item;
|
||||
Node left, right;
|
||||
Node left;
|
||||
Node right;
|
||||
}
|
||||
|
||||
// Using an arraylist to store the inorder traversal of the given binary tree
|
||||
|
@ -47,7 +47,8 @@ public final class VerticalOrderTraversal {
|
||||
|
||||
/* min and max stores leftmost and right most index to
|
||||
later print the tree in vertical fashion.*/
|
||||
int max = 0, min = 0;
|
||||
int max = 0;
|
||||
int min = 0;
|
||||
queue.offer(root);
|
||||
index.offer(0);
|
||||
|
||||
|
Reference in New Issue
Block a user