style: enable LocalVariableName in CheckStyle (#5191)

* style: enable LocalVariableName in checkstyle

* Removed minor bug

* Resolved Method Name Bug

* Changed names according to suggestions
This commit is contained in:
S. Utkarsh
2024-05-28 23:59:28 +05:30
committed by GitHub
parent 81cb09b1f8
commit 25d711c5d8
45 changed files with 418 additions and 417 deletions

View File

@ -54,23 +54,23 @@ public final class BipartiteGrapfDFS {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine().trim());
while (t-- > 0) {
String[] S = read.readLine().trim().split(" ");
int V = Integer.parseInt(S[0]);
int E = Integer.parseInt(S[1]);
String[] str1 = read.readLine().trim().split(" ");
int numVertices = Integer.parseInt(str1[0]);
int numEdges = Integer.parseInt(str1[1]);
ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
for (int i = 0; i < V; i++) {
for (int i = 0; i < numVertices; i++) {
adj.add(new ArrayList<>());
}
for (int i = 0; i < E; i++) {
String[] s = read.readLine().trim().split(" ");
int u = Integer.parseInt(s[0]);
int v = Integer.parseInt(s[1]);
adj.get(u).add(v);
adj.get(v).add(u);
for (int i = 0; i < numEdges; i++) {
String[] str2 = read.readLine().trim().split(" ");
int vertexU = Integer.parseInt(str2[0]);
int vertexV = Integer.parseInt(str2[1]);
adj.get(vertexU).add(vertexV);
adj.get(vertexV).add(vertexU);
}
boolean ans = isBipartite(V, adj);
boolean ans = isBipartite(numVertices, adj);
if (ans) {
System.out.println("YES");
} else {

View File

@ -8,18 +8,18 @@ class dijkstras {
int k = 9;
int minDist(int[] dist, Boolean[] Set) {
int minDist(int[] dist, Boolean[] set) {
int min = Integer.MAX_VALUE;
int min_index = -1;
int minIndex = -1;
for (int r = 0; r < k; r++) {
if (!Set[r] && dist[r] <= min) {
if (!set[r] && dist[r] <= min) {
min = dist[r];
min_index = r;
minIndex = r;
}
}
return min_index;
return minIndex;
}
void print(int[] dist) {
@ -31,22 +31,22 @@ class dijkstras {
void dijkstra(int[][] graph, int src) {
int[] dist = new int[k];
Boolean[] Set = new Boolean[k];
Boolean[] set = new Boolean[k];
for (int i = 0; i < k; i++) {
dist[i] = Integer.MAX_VALUE;
Set[i] = Boolean.FALSE;
set[i] = Boolean.FALSE;
}
dist[src] = 0;
for (int c = 0; c < k - 1; c++) {
int u = minDist(dist, Set);
int u = minDist(dist, set);
Set[u] = Boolean.TRUE;
set[u] = Boolean.TRUE;
for (int v = 0; v < k; v++) {
if (!Set[v] && graph[u][v] != 0 && dist[u] != Integer.MAX_VALUE && dist[u] + graph[u][v] < dist[v]) {
if (!set[v] && graph[u][v] != 0 && dist[u] != Integer.MAX_VALUE && dist[u] + graph[u][v] < dist[v]) {
dist[v] = dist[u] + graph[u][v];
}
}

View File

@ -15,16 +15,16 @@ class PrimMST {
int minKey(int[] key, Boolean[] mstSet) {
// Initialize min value
int min = Integer.MAX_VALUE;
int min_index = -1;
int minIndex = -1;
for (int v = 0; v < V; v++) {
if (!mstSet[v] && key[v] < min) {
min = key[v];
min_index = v;
minIndex = v;
}
}
return min_index;
return minIndex;
}
// A utility function to print the constructed MST stored in

View File

@ -11,7 +11,7 @@ public final class Main {
int key;
HashMap h = new HashMap(7);
Scanner In = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Enter your Choice :");
@ -20,18 +20,18 @@ public final class Main {
System.out.println("3. Print Table");
System.out.println("4. Exit");
choice = In.nextInt();
choice = scan.nextInt();
switch (choice) {
case 1: {
System.out.println("Enter the Key: ");
key = In.nextInt();
key = scan.nextInt();
h.insertHash(key);
break;
}
case 2: {
System.out.println("Enter the Key delete: ");
key = In.nextInt();
key = scan.nextInt();
h.deleteHash(key);
break;
}
@ -41,7 +41,7 @@ public final class Main {
break;
}
case 4: {
In.close();
scan.close();
return;
}
default: {

View File

@ -11,7 +11,7 @@ public final class MainCuckooHashing {
int key;
HashMapCuckooHashing h = new HashMapCuckooHashing(7);
Scanner In = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("_________________________");
@ -24,18 +24,18 @@ public final class MainCuckooHashing {
System.out.println("6. Check load factor");
System.out.println("7. Rehash Current Table");
choice = In.nextInt();
choice = scan.nextInt();
switch (choice) {
case 1: {
System.out.println("Enter the Key: ");
key = In.nextInt();
key = scan.nextInt();
h.insertKey2HashTable(key);
break;
}
case 2: {
System.out.println("Enter the Key delete: ");
key = In.nextInt();
key = scan.nextInt();
h.deleteKeyFromHashTable(key);
break;
}
@ -45,12 +45,12 @@ public final class MainCuckooHashing {
break;
}
case 4: {
In.close();
scan.close();
return;
}
case 5: {
System.out.println("Enter the Key to find and print: ");
key = In.nextInt();
key = scan.nextInt();
System.out.println("Key: " + key + " is at index: " + h.findKeyInTable(key) + "\n");
break;
}

View File

@ -108,25 +108,25 @@ public class CursorLinkedList<T> {
Objects.requireNonNull(element);
// case element is in the head
T temp_element = cursorSpace[head].element;
int temp_next = cursorSpace[head].next;
if (temp_element.equals(element)) {
T tempElement = cursorSpace[head].element;
int tempNext = cursorSpace[head].next;
if (tempElement.equals(element)) {
free(head);
head = temp_next;
head = tempNext;
} else { // otherwise cases
int prev_index = head;
int current_index = cursorSpace[prev_index].next;
int prevIndex = head;
int currentIndex = cursorSpace[prevIndex].next;
while (current_index != -1) {
T current_element = cursorSpace[current_index].element;
if (current_element.equals(element)) {
cursorSpace[prev_index].next = cursorSpace[current_index].next;
free(current_index);
while (currentIndex != -1) {
T currentElement = cursorSpace[currentIndex].element;
if (currentElement.equals(element)) {
cursorSpace[prevIndex].next = cursorSpace[currentIndex].next;
free(currentIndex);
break;
}
prev_index = current_index;
current_index = cursorSpace[prev_index].next;
prevIndex = currentIndex;
currentIndex = cursorSpace[prevIndex].next;
}
}
@ -134,11 +134,11 @@ public class CursorLinkedList<T> {
}
private void free(int index) {
Node<T> os_node = cursorSpace[os];
int os_next = os_node.next;
Node<T> osNode = cursorSpace[os];
int osNext = osNode.next;
cursorSpace[os].next = index;
cursorSpace[index].element = null;
cursorSpace[index].next = os_next;
cursorSpace[index].next = osNext;
}
public void append(T element) {

View File

@ -23,17 +23,17 @@ public class ReverseKGroup {
Node prev = null;
int count1 = 0;
Node curr = head;
Node Next = null;
Node next = null;
while (curr != null && count1 < k) {
Next = curr.next;
next = curr.next;
curr.next = prev;
prev = curr;
curr = Next;
curr = next;
count1++;
}
if (Next != null) {
head.next = reverse(Next, count - k, k);
if (next != null) {
head.next = reverse(next, count - k, k);
}
return prev;
}

View File

@ -11,20 +11,20 @@ public class NodeStack<Item> {
* Entry point for the program.
*/
public static void main(String[] args) {
NodeStack<Integer> Stack = new NodeStack<Integer>();
NodeStack<Integer> stack = new NodeStack<Integer>();
Stack.push(3);
Stack.push(4);
Stack.push(5);
stack.push(3);
stack.push(4);
stack.push(5);
System.out.println("Testing :");
Stack.print(); // prints : 5 4 3
stack.print(); // prints : 5 4 3
Integer x = Stack.pop(); // x = 5
Stack.push(1);
Stack.push(8);
Integer y = Stack.peek(); // y = 8
Integer x = stack.pop(); // x = 5
stack.push(1);
stack.push(8);
Integer y = stack.peek(); // y = 8
System.out.println("Testing :");
Stack.print(); // prints : 8 1 4 3
stack.print(); // prints : 8 1 4 3
System.out.println("Testing :");
System.out.println("x : " + x);

View File

@ -112,10 +112,10 @@ public class AVLSimple {
private Node rightRotate(Node c) {
Node b = c.left;
Node T3 = b.right;
Node t3 = b.right;
b.right = c;
c.left = T3;
c.left = t3;
c.height = Math.max(height(c.left), height(c.right)) + 1;
b.height = Math.max(height(b.left), height(b.right)) + 1;
return b;
@ -123,10 +123,10 @@ public class AVLSimple {
private Node leftRotate(Node c) {
Node b = c.right;
Node T3 = b.left;
Node t3 = b.left;
b.left = c;
c.right = T3;
c.right = t3;
c.height = Math.max(height(c.left), height(c.right)) + 1;
b.height = Math.max(height(b.left), height(b.right)) + 1;
return b;

View File

@ -60,13 +60,13 @@ class Tree {
HashSet<Integer> set = new HashSet<>();
// Create a queue and add root to it
Queue<QItem> Q = new LinkedList<QItem>();
Q.add(new QItem(root, 0)); // Horizontal distance of root is 0
Queue<QItem> queue = new LinkedList<QItem>();
queue.add(new QItem(root, 0)); // Horizontal distance of root is 0
// Standard BFS or level order traversal loop
while (!Q.isEmpty()) {
while (!queue.isEmpty()) {
// Remove the front item and get its details
QItem qi = Q.remove();
QItem qi = queue.remove();
int hd = qi.hd;
TreeNode n = qi.node;
@ -79,10 +79,10 @@ class Tree {
// Enqueue left and right children of current node
if (n.left != null) {
Q.add(new QItem(n.left, hd - 1));
queue.add(new QItem(n.left, hd - 1));
}
if (n.right != null) {
Q.add(new QItem(n.right, hd + 1));
queue.add(new QItem(n.right, hd + 1));
}
}
}

View File

@ -10,9 +10,9 @@ public class SegmentTree {
public SegmentTree(int n, int[] arr) {
this.n = n;
int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));
int seg_size = 2 * (int) Math.pow(2, x) - 1;
int segSize = 2 * (int) Math.pow(2, x) - 1;
this.seg_t = new int[seg_size];
this.seg_t = new int[segSize];
this.arr = arr;
this.n = n;
constructTree(arr, 0, n - 1, 0);