style: enable MemberName in checkstyle (#5193)

* style: enable MemberName in checkstyle

* style: simply uncomment `MemberName`

---------

Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com>
This commit is contained in:
S. Utkarsh
2024-05-30 02:14:14 +05:30
committed by GitHub
parent d2bfb100b2
commit a6e873deef
17 changed files with 168 additions and 168 deletions

View File

@ -4,12 +4,12 @@ import java.util.Scanner;
public class FloydWarshall {
private int[][] DistanceMatrix;
private int[][] distanceMatrix;
private int numberofvertices; // number of vertices in the graph
public static final int INFINITY = 999;
public FloydWarshall(int numberofvertices) {
DistanceMatrix = new int[numberofvertices + 1][numberofvertices + 1]; // stores the value of distance from all the possible path form the source
distanceMatrix = new int[numberofvertices + 1][numberofvertices + 1]; // stores the value of distance from all the possible path form the source
// vertex to destination vertex
// The matrix is initialized with 0's by default
this.numberofvertices = numberofvertices;
@ -18,17 +18,17 @@ public class FloydWarshall {
public void floydwarshall(int[][] AdjacencyMatrix) { // calculates all the distances from source to destination vertex
for (int source = 1; source <= numberofvertices; source++) {
for (int destination = 1; destination <= numberofvertices; destination++) {
DistanceMatrix[source][destination] = AdjacencyMatrix[source][destination];
distanceMatrix[source][destination] = AdjacencyMatrix[source][destination];
}
}
for (int intermediate = 1; intermediate <= numberofvertices; intermediate++) {
for (int source = 1; source <= numberofvertices; source++) {
for (int destination = 1; destination <= numberofvertices; destination++) {
if (DistanceMatrix[source][intermediate] + DistanceMatrix[intermediate][destination] < DistanceMatrix[source][destination]) { // calculated distance it get replaced as
if (distanceMatrix[source][intermediate] + distanceMatrix[intermediate][destination] < distanceMatrix[source][destination]) { // calculated distance it get replaced as
// new shortest distance // if the new
// distance calculated is less then the
// earlier shortest
DistanceMatrix[source][destination] = DistanceMatrix[source][intermediate] + DistanceMatrix[intermediate][destination];
distanceMatrix[source][destination] = distanceMatrix[source][intermediate] + distanceMatrix[intermediate][destination];
}
}
}
@ -40,7 +40,7 @@ public class FloydWarshall {
for (int source = 1; source <= numberofvertices; source++) {
System.out.print(source + "\t");
for (int destination = 1; destination <= numberofvertices; destination++) {
System.out.print(DistanceMatrix[source][destination] + "\t");
System.out.print(distanceMatrix[source][destination] + "\t");
}
System.out.println();
}

View File

@ -8,7 +8,7 @@ package com.thealgorithms.datastructures.graphs;
*/
public class HamiltonianCycle {
private int V;
private int vertex;
private int pathCount;
private int[] cycle;
private int[][] graph;
@ -22,8 +22,8 @@ public class HamiltonianCycle {
* else returns 1D array with value -1.
*/
public int[] findHamiltonianCycle(int[][] graph) {
this.V = graph.length;
this.cycle = new int[this.V + 1];
this.vertex = graph.length;
this.cycle = new int[this.vertex + 1];
// Initialize path array with -1 value
for (int i = 0; i < this.cycle.length; i++) {
@ -53,17 +53,17 @@ public class HamiltonianCycle {
* @returns true if path is found false otherwise
*/
public boolean isPathFound(int vertex) {
boolean isLastVertexConnectedToStart = this.graph[vertex][0] == 1 && this.pathCount == this.V;
boolean isLastVertexConnectedToStart = this.graph[vertex][0] == 1 && this.pathCount == this.vertex;
if (isLastVertexConnectedToStart) {
return true;
}
/** all vertices selected but last vertex not linked to 0 **/
if (this.pathCount == this.V) {
if (this.pathCount == this.vertex) {
return false;
}
for (int v = 0; v < this.V; v++) {
for (int v = 0; v < this.vertex; v++) {
/** if connected **/
if (this.graph[vertex][v] == 1) {
/** add to path **/

View File

@ -48,17 +48,17 @@ class AdjacencyMatrixGraph {
/**
* The number of vertices in the graph
*/
private int _numberOfVertices;
private int vertexCount;
/**
* The number of edges in the graph
*/
private int _numberOfEdges;
private int edgeCount;
/**
* The adjacency matrix for the graph
*/
private int[][] _adjacency;
private int[][] adjMatrix;
/**
* Static variables to define whether or not an edge exists in the adjacency
@ -87,16 +87,16 @@ class AdjacencyMatrixGraph {
* @param newNumberOfVertices the new number of vertices
*/
private void setNumberOfVertices(int newNumberOfVertices) {
this._numberOfVertices = newNumberOfVertices;
this.vertexCount = newNumberOfVertices;
}
/**
* Getter for `this._numberOfVertices`
* Getter for `this.vertexCount`
*
* @return the number of vertices in the graph
*/
public int numberOfVertices() {
return this._numberOfVertices;
return this.vertexCount;
}
/**
@ -106,16 +106,16 @@ class AdjacencyMatrixGraph {
*
*/
private void setNumberOfEdges(int newNumberOfEdges) {
this._numberOfEdges = newNumberOfEdges;
this.edgeCount = newNumberOfEdges;
}
/**
* Getter for `this._numberOfEdges`
* Getter for `this.edgeCount`
*
* @return the number of edges
*/
public int numberOfEdges() {
return this._numberOfEdges;
return this.edgeCount;
}
/**
@ -124,7 +124,7 @@ class AdjacencyMatrixGraph {
* @param newAdjacency the new adjaceny matrix
*/
private void setAdjacency(int[][] newAdjacency) {
this._adjacency = newAdjacency;
this.adjMatrix = newAdjacency;
}
/**
@ -133,7 +133,7 @@ class AdjacencyMatrixGraph {
* @return the adjacency matrix
*/
private int[][] adjacency() {
return this._adjacency;
return this.adjMatrix;
}
/**
@ -222,12 +222,12 @@ class AdjacencyMatrixGraph {
*/
public List<Integer> depthFirstOrder(int startVertex) {
// If the startVertex is invalid, return an empty list
if (startVertex >= _numberOfVertices || startVertex < 0) {
if (startVertex >= vertexCount || startVertex < 0) {
return new ArrayList<Integer>();
}
// Create an array to track the visited vertices
boolean[] visited = new boolean[_numberOfVertices];
boolean[] visited = new boolean[vertexCount];
// Create a list to keep track of the order of our traversal
ArrayList<Integer> orderList = new ArrayList<Integer>();
@ -259,7 +259,7 @@ class AdjacencyMatrixGraph {
orderList.add(currentVertex);
// Get the adjacency array for this vertex
int[] adjacent = _adjacency[currentVertex];
int[] adjacent = adjMatrix[currentVertex];
for (int i = 0; i < adjacent.length; i++) { // we are considering exploring, recurse on it // If an edge exists between the
// currentVertex and the vertex
if (adjacent[i] == AdjacencyMatrixGraph.EDGE_EXIST) {
@ -277,12 +277,12 @@ class AdjacencyMatrixGraph {
*/
public List<Integer> breadthFirstOrder(int startVertex) {
// If the specified startVertex is invalid, return an empty list
if (startVertex >= _numberOfVertices || startVertex < 0) {
if (startVertex >= vertexCount || startVertex < 0) {
return new ArrayList<Integer>();
}
// Create an array to keep track of the visited vertices
boolean[] visited = new boolean[_numberOfVertices];
boolean[] visited = new boolean[vertexCount];
// Create a list to keep track of the ordered vertices
ArrayList<Integer> orderList = new ArrayList<Integer>();
@ -309,7 +309,7 @@ class AdjacencyMatrixGraph {
// Get the adjacency array for the currentVertex and
// check each node
int[] adjacent = _adjacency[currentVertex];
int[] adjacent = adjMatrix[currentVertex];
for (int vertex = 0; vertex < adjacent.length; vertex++) { // vertex we are considering exploring, we add it to the queue // If an
// edge exists between the current vertex and the
if (adjacent[vertex] == AdjacencyMatrixGraph.EDGE_EXIST) {
@ -336,7 +336,7 @@ class AdjacencyMatrixGraph {
for (int i = 0; i < this.numberOfVertices(); i++) {
s = s + i + " : ";
for (int j = 0; j < this.numberOfVertices(); j++) {
s = s + this._adjacency[i][j] + " ";
s = s + this.adjMatrix[i][j] + " ";
}
s = s + "\n";
}

View File

@ -56,9 +56,9 @@ import java.util.Stack;
public class TarjansAlgorithm {
// Timer for tracking lowtime and insertion time
private int Time;
private int time;
private List<List<Integer>> SCClist = new ArrayList<List<Integer>>();
private List<List<Integer>> sccList = new ArrayList<List<Integer>>();
public List<List<Integer>> stronglyConnectedComponents(int V, List<List<Integer>> graph) {
@ -85,15 +85,15 @@ public class TarjansAlgorithm {
if (insertionTime[i] == -1) stronglyConnCompsUtil(i, lowTime, insertionTime, isInStack, st, graph);
}
return SCClist;
return sccList;
}
private void stronglyConnCompsUtil(int u, int[] lowTime, int[] insertionTime, boolean[] isInStack, Stack<Integer> st, List<List<Integer>> graph) {
// Initialize insertion time and lowTime value of current node
insertionTime[u] = Time;
lowTime[u] = Time;
Time += 1;
insertionTime[u] = time;
lowTime[u] = time;
time += 1;
// Push current node into stack
isInStack[u] = true;
@ -123,7 +123,7 @@ public class TarjansAlgorithm {
scc.add(w);
isInStack[w] = false;
}
SCClist.add(scc);
sccList.add(scc);
}
}
}