mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-25 05:22:39 +08:00
style: enable ParameterName
in CheckStyle. (#5196)
* Enabled: ParameterName in CheckStyle. * Refactored to fix bug caused by selfAssignment of variables in VectorCrossproduct class
This commit is contained in:

committed by
GitHub

parent
2568b96784
commit
c42b1c940c
@ -18,14 +18,14 @@ public final class BipartiteGrapfDFS {
|
||||
private BipartiteGrapfDFS() {
|
||||
}
|
||||
|
||||
private static boolean bipartite(int V, ArrayList<ArrayList<Integer>> adj, int[] color, int node) {
|
||||
private static boolean bipartite(int v, ArrayList<ArrayList<Integer>> adj, int[] color, int node) {
|
||||
if (color[node] == -1) {
|
||||
color[node] = 1;
|
||||
}
|
||||
for (Integer it : adj.get(node)) {
|
||||
if (color[it] == -1) {
|
||||
color[it] = 1 - color[node];
|
||||
if (!bipartite(V, adj, color, it)) {
|
||||
if (!bipartite(v, adj, color, it)) {
|
||||
return false;
|
||||
}
|
||||
} else if (color[it] == color[node]) {
|
||||
@ -35,14 +35,14 @@ public final class BipartiteGrapfDFS {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isBipartite(int V, ArrayList<ArrayList<Integer>> adj) {
|
||||
public static boolean isBipartite(int v, ArrayList<ArrayList<Integer>> adj) {
|
||||
// Code here
|
||||
int[] color = new int[V + 1];
|
||||
int[] color = new int[v + 1];
|
||||
Arrays.fill(color, -1);
|
||||
|
||||
for (int i = 0; i < V; i++) {
|
||||
for (int i = 0; i < v; i++) {
|
||||
if (color[i] == -1) {
|
||||
if (!bipartite(V, adj, color, i)) {
|
||||
if (!bipartite(v, adj, color, i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,10 @@ public class FloydWarshall {
|
||||
this.numberofvertices = numberofvertices;
|
||||
}
|
||||
|
||||
public void floydwarshall(int[][] AdjacencyMatrix) { // calculates all the distances from source to destination vertex
|
||||
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++) {
|
||||
|
@ -60,7 +60,7 @@ public class TarjansAlgorithm {
|
||||
|
||||
private List<List<Integer>> sccList = new ArrayList<List<Integer>>();
|
||||
|
||||
public List<List<Integer>> stronglyConnectedComponents(int V, List<List<Integer>> graph) {
|
||||
public List<List<Integer>> stronglyConnectedComponents(int v, List<List<Integer>> graph) {
|
||||
|
||||
// Initially all vertices as unvisited, insertion and low time are undefined
|
||||
|
||||
@ -68,20 +68,20 @@ public class TarjansAlgorithm {
|
||||
|
||||
// lowTime: indicates the earliest visited vertex (the vertex with minimum insertion time)
|
||||
// that can be reached from a subtree rooted with a particular node.
|
||||
int[] lowTime = new int[V];
|
||||
int[] insertionTime = new int[V];
|
||||
for (int i = 0; i < V; i++) {
|
||||
int[] lowTime = new int[v];
|
||||
int[] insertionTime = new int[v];
|
||||
for (int i = 0; i < v; i++) {
|
||||
insertionTime[i] = -1;
|
||||
lowTime[i] = -1;
|
||||
}
|
||||
|
||||
// To check if element is present in stack
|
||||
boolean[] isInStack = new boolean[V];
|
||||
boolean[] isInStack = new boolean[v];
|
||||
|
||||
// Store nodes during DFS
|
||||
Stack<Integer> st = new Stack<Integer>();
|
||||
|
||||
for (int i = 0; i < V; i++) {
|
||||
for (int i = 0; i < v; i++) {
|
||||
if (insertionTime[i] == -1) stronglyConnCompsUtil(i, lowTime, insertionTime, isInStack, st, graph);
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@ public class GenericHashMapUsingArray<K, V> {
|
||||
// 75, then adding 76th item it will double the size, copy all elements
|
||||
// & then add 76th item.
|
||||
|
||||
private void initBuckets(int N) {
|
||||
buckets = new LinkedList[N];
|
||||
private void initBuckets(int n) {
|
||||
buckets = new LinkedList[n];
|
||||
for (int i = 0; i < buckets.length; i++) {
|
||||
buckets[i] = new LinkedList<>();
|
||||
}
|
||||
|
@ -13,15 +13,15 @@ public class Merge_K_SortedLinkedlist {
|
||||
* This function merge K sorted LinkedList
|
||||
*
|
||||
* @param a array of LinkedList
|
||||
* @param N size of array
|
||||
* @param n size of array
|
||||
* @return node
|
||||
*/
|
||||
Node mergeKList(Node[] a, int N) {
|
||||
Node mergeKList(Node[] a, int n) {
|
||||
// Min Heap
|
||||
PriorityQueue<Node> min = new PriorityQueue<>(Comparator.comparingInt(x -> x.data));
|
||||
|
||||
// adding head of all linkedList in min heap
|
||||
min.addAll(Arrays.asList(a).subList(0, N));
|
||||
min.addAll(Arrays.asList(a).subList(0, n));
|
||||
|
||||
// Make new head among smallest heads in K linkedList
|
||||
Node head = min.poll();
|
||||
|
@ -32,16 +32,16 @@ public class SegmentTree {
|
||||
|
||||
/* A function which will update the value at a index i. This will be called by the
|
||||
update function internally*/
|
||||
private void updateTree(int start, int end, int index, int diff, int seg_index) {
|
||||
private void updateTree(int start, int end, int index, int diff, int segIndex) {
|
||||
if (index < start || index > end) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.segTree[seg_index] += diff;
|
||||
this.segTree[segIndex] += diff;
|
||||
if (start != end) {
|
||||
int mid = start + (end - start) / 2;
|
||||
updateTree(start, mid, index, diff, seg_index * 2 + 1);
|
||||
updateTree(mid + 1, end, index, diff, seg_index * 2 + 2);
|
||||
updateTree(start, mid, index, diff, segIndex * 2 + 1);
|
||||
updateTree(mid + 1, end, index, diff, segIndex * 2 + 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,17 +58,17 @@ public class SegmentTree {
|
||||
|
||||
/* A function to get the sum of the elements from index l to index r. This will be called
|
||||
* internally*/
|
||||
private int getSumTree(int start, int end, int q_start, int q_end, int seg_index) {
|
||||
if (q_start <= start && q_end >= end) {
|
||||
return this.segTree[seg_index];
|
||||
private int getSumTree(int start, int end, int qStart, int qEnd, int segIndex) {
|
||||
if (qStart <= start && qEnd >= end) {
|
||||
return this.segTree[segIndex];
|
||||
}
|
||||
|
||||
if (q_start > end || q_end < start) {
|
||||
if (qStart > end || qEnd < start) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mid = start + (end - start) / 2;
|
||||
return (getSumTree(start, mid, q_start, q_end, seg_index * 2 + 1) + getSumTree(mid + 1, end, q_start, q_end, seg_index * 2 + 2));
|
||||
return (getSumTree(start, mid, qStart, qEnd, segIndex * 2 + 1) + getSumTree(mid + 1, end, qStart, qEnd, segIndex * 2 + 2));
|
||||
}
|
||||
|
||||
/* A function to query the sum of the subarray [start...end]*/
|
||||
|
Reference in New Issue
Block a user