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

@@ -3,12 +3,12 @@ package com.thealgorithms.datastructures.trees;
public class FenwickTree {
private int n;
private int[] fen_t;
private int[] fenTree;
/* Constructor which takes the size of the array as a parameter */
public FenwickTree(int n) {
this.n = n;
this.fen_t = new int[n + 1];
this.fenTree = new int[n + 1];
}
/* A function which will add the element val at index i*/
@@ -16,7 +16,7 @@ public class FenwickTree {
// As index starts from 0, increment the index by 1
i += 1;
while (i <= n) {
fen_t[i] += val;
fenTree[i] += val;
i += i & (-i);
}
}
@@ -27,7 +27,7 @@ public class FenwickTree {
i += 1;
int cumSum = 0;
while (i > 0) {
cumSum += fen_t[i];
cumSum += fenTree[i];
i -= i & (-i);
}
return cumSum;

View File

@@ -7,13 +7,13 @@ import java.util.Scanner;
*/
public class RedBlackBST {
private final int R = 0;
private final int B = 1;
private final int red = 0;
private final int black = 1;
private class Node {
int key = -1;
int color = B;
int color = black;
Node left = nil;
Node right = nil;
Node p = nil;
@@ -31,7 +31,7 @@ public class RedBlackBST {
return;
}
printTree(node.left);
System.out.print(((node.color == R) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n");
System.out.print(((node.color == red) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n");
printTree(node.right);
}
@@ -39,7 +39,7 @@ public class RedBlackBST {
if (node == nil) {
return;
}
System.out.print(((node.color == R) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n");
System.out.print(((node.color == red) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n");
printTreepre(node.left);
printTreepre(node.right);
}
@@ -66,10 +66,10 @@ public class RedBlackBST {
Node temp = root;
if (root == nil) {
root = node;
node.color = B;
node.color = black;
node.p = nil;
} else {
node.color = R;
node.color = red;
while (true) {
if (node.key < temp.key) {
if (temp.left == nil) {
@@ -94,15 +94,15 @@ public class RedBlackBST {
}
private void fixTree(Node node) {
while (node.p.color == R) {
while (node.p.color == red) {
Node y = nil;
if (node.p == node.p.p.left) {
y = node.p.p.right;
if (y != nil && y.color == R) {
node.p.color = B;
y.color = B;
node.p.p.color = R;
if (y != nil && y.color == red) {
node.p.color = black;
y.color = black;
node.p.p.color = red;
node = node.p.p;
continue;
}
@@ -110,15 +110,15 @@ public class RedBlackBST {
node = node.p;
rotateLeft(node);
}
node.p.color = B;
node.p.p.color = R;
node.p.color = black;
node.p.p.color = red;
rotateRight(node.p.p);
} else {
y = node.p.p.left;
if (y != nil && y.color == R) {
node.p.color = B;
y.color = B;
node.p.p.color = R;
if (y != nil && y.color == red) {
node.p.color = black;
y.color = black;
node.p.p.color = red;
node = node.p.p;
continue;
}
@@ -126,12 +126,12 @@ public class RedBlackBST {
node = node.p;
rotateRight(node);
}
node.p.color = B;
node.p.p.color = R;
node.p.color = black;
node.p.p.color = red;
rotateLeft(node.p.p);
}
}
root.color = B;
root.color = black;
}
void rotateLeft(Node node) {
@@ -234,67 +234,67 @@ public class RedBlackBST {
y.left.p = y;
y.color = z.color;
}
if (yorigcolor == B) {
if (yorigcolor == black) {
deleteFixup(x);
}
return true;
}
void deleteFixup(Node x) {
while (x != root && x.color == B) {
while (x != root && x.color == black) {
if (x == x.p.left) {
Node w = x.p.right;
if (w.color == R) {
w.color = B;
x.p.color = R;
if (w.color == red) {
w.color = black;
x.p.color = red;
rotateLeft(x.p);
w = x.p.right;
}
if (w.left.color == B && w.right.color == B) {
w.color = R;
if (w.left.color == black && w.right.color == black) {
w.color = red;
x = x.p;
continue;
} else if (w.right.color == B) {
w.left.color = B;
w.color = R;
} else if (w.right.color == black) {
w.left.color = black;
w.color = red;
rotateRight(w);
w = x.p.right;
}
if (w.right.color == R) {
if (w.right.color == red) {
w.color = x.p.color;
x.p.color = B;
w.right.color = B;
x.p.color = black;
w.right.color = black;
rotateLeft(x.p);
x = root;
}
} else {
Node w = x.p.left;
if (w.color == R) {
w.color = B;
x.p.color = R;
if (w.color == red) {
w.color = black;
x.p.color = red;
rotateRight(x.p);
w = x.p.left;
}
if (w.right.color == B && w.left.color == B) {
w.color = R;
if (w.right.color == black && w.left.color == black) {
w.color = red;
x = x.p;
continue;
} else if (w.left.color == B) {
w.right.color = B;
w.color = R;
} else if (w.left.color == black) {
w.right.color = black;
w.color = red;
rotateLeft(w);
w = x.p.left;
}
if (w.left.color == R) {
if (w.left.color == red) {
w.color = x.p.color;
x.p.color = B;
w.left.color = B;
x.p.color = black;
w.left.color = black;
rotateRight(x.p);
x = root;
}
}
}
x.color = B;
x.color = black;
}
public void insertDemo() {

View File

@@ -2,7 +2,7 @@ package com.thealgorithms.datastructures.trees;
public class SegmentTree {
private int[] seg_t;
private int[] segTree;
private int n;
private int[] arr;
@@ -12,7 +12,7 @@ public class SegmentTree {
int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));
int segSize = 2 * (int) Math.pow(2, x) - 1;
this.seg_t = new int[segSize];
this.segTree = new int[segSize];
this.arr = arr;
this.n = n;
constructTree(arr, 0, n - 1, 0);
@@ -21,13 +21,13 @@ public class SegmentTree {
/* A function which will create the segment tree*/
public final int constructTree(int[] arr, int start, int end, int index) {
if (start == end) {
this.seg_t[index] = arr[start];
this.segTree[index] = arr[start];
return arr[start];
}
int mid = start + (end - start) / 2;
this.seg_t[index] = constructTree(arr, start, mid, index * 2 + 1) + constructTree(arr, mid + 1, end, index * 2 + 2);
return this.seg_t[index];
this.segTree[index] = constructTree(arr, start, mid, index * 2 + 1) + constructTree(arr, mid + 1, end, index * 2 + 2);
return this.segTree[index];
}
/* A function which will update the value at a index i. This will be called by the
@@ -37,7 +37,7 @@ public class SegmentTree {
return;
}
this.seg_t[seg_index] += diff;
this.segTree[seg_index] += diff;
if (start != end) {
int mid = start + (end - start) / 2;
updateTree(start, mid, index, diff, seg_index * 2 + 1);
@@ -60,7 +60,7 @@ public class SegmentTree {
* 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.seg_t[seg_index];
return this.segTree[seg_index];
}
if (q_start > end || q_end < start) {