mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-22 03:24:57 +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
@ -12,44 +12,44 @@ public final class BoundaryFill {
|
||||
* Get the color at the given co-odrinates of a 2D image
|
||||
*
|
||||
* @param image The image to be filled
|
||||
* @param x_co_ordinate The x co-ordinate of which color is to be obtained
|
||||
* @param y_co_ordinate The y co-ordinate of which color is to be obtained
|
||||
* @param xCoordinate The x co-ordinate of which color is to be obtained
|
||||
* @param yCoordinate The y co-ordinate of which color is to be obtained
|
||||
*/
|
||||
public static int getPixel(int[][] image, int x_co_ordinate, int y_co_ordinate) {
|
||||
return image[x_co_ordinate][y_co_ordinate];
|
||||
public static int getPixel(int[][] image, int xCoordinate, int yCoordinate) {
|
||||
return image[xCoordinate][yCoordinate];
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the color at the given co-odrinates of a 2D image
|
||||
*
|
||||
* @param image The image to be filed
|
||||
* @param x_co_ordinate The x co-ordinate at which color is to be filled
|
||||
* @param y_co_ordinate The y co-ordinate at which color is to be filled
|
||||
* @param xCoordinate The x co-ordinate at which color is to be filled
|
||||
* @param yCoordinate The y co-ordinate at which color is to be filled
|
||||
*/
|
||||
public static void putPixel(int[][] image, int x_co_ordinate, int y_co_ordinate, int new_color) {
|
||||
image[x_co_ordinate][y_co_ordinate] = new_color;
|
||||
public static void putPixel(int[][] image, int xCoordinate, int yCoordinate, int newColor) {
|
||||
image[xCoordinate][yCoordinate] = newColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the 2D image with new color
|
||||
*
|
||||
* @param image The image to be filed
|
||||
* @param x_co_ordinate The x co-ordinate at which color is to be filled
|
||||
* @param y_co_ordinate The y co-ordinate at which color is to be filled
|
||||
* @param new_color The new color which to be filled in the image
|
||||
* @param boundary_color The old color which is to be replaced in the image
|
||||
* @param xCoordinate The x co-ordinate at which color is to be filled
|
||||
* @param yCoordinate The y co-ordinate at which color is to be filled
|
||||
* @param newColor The new color which to be filled in the image
|
||||
* @param boundaryColor The old color which is to be replaced in the image
|
||||
*/
|
||||
public static void boundaryFill(int[][] image, int x_co_ordinate, int y_co_ordinate, int new_color, int boundary_color) {
|
||||
if (x_co_ordinate >= 0 && y_co_ordinate >= 0 && getPixel(image, x_co_ordinate, y_co_ordinate) != new_color && getPixel(image, x_co_ordinate, y_co_ordinate) != boundary_color) {
|
||||
putPixel(image, x_co_ordinate, y_co_ordinate, new_color);
|
||||
boundaryFill(image, x_co_ordinate + 1, y_co_ordinate, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate - 1, y_co_ordinate, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate, y_co_ordinate + 1, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate, y_co_ordinate - 1, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate + 1, y_co_ordinate - 1, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate - 1, y_co_ordinate + 1, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate + 1, y_co_ordinate + 1, new_color, boundary_color);
|
||||
boundaryFill(image, x_co_ordinate - 1, y_co_ordinate - 1, new_color, boundary_color);
|
||||
public static void boundaryFill(int[][] image, int xCoordinate, int yCoordinate, int newColor, int boundaryColor) {
|
||||
if (xCoordinate >= 0 && yCoordinate >= 0 && getPixel(image, xCoordinate, yCoordinate) != newColor && getPixel(image, xCoordinate, yCoordinate) != boundaryColor) {
|
||||
putPixel(image, xCoordinate, yCoordinate, newColor);
|
||||
boundaryFill(image, xCoordinate + 1, yCoordinate, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate - 1, yCoordinate, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate, yCoordinate + 1, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate, yCoordinate - 1, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate + 1, yCoordinate - 1, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate - 1, yCoordinate + 1, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate + 1, yCoordinate + 1, newColor, boundaryColor);
|
||||
boundaryFill(image, xCoordinate - 1, yCoordinate - 1, newColor, boundaryColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,9 +8,9 @@ public final class BruteForceKnapsack {
|
||||
// Returns the maximum value that
|
||||
// can be put in a knapsack of
|
||||
// capacity W
|
||||
static int knapSack(int W, int[] wt, int[] val, int n) {
|
||||
static int knapSack(int w, int[] wt, int[] val, int n) {
|
||||
// Base Case
|
||||
if (n == 0 || W == 0) {
|
||||
if (n == 0 || w == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -18,13 +18,13 @@ public final class BruteForceKnapsack {
|
||||
// more than Knapsack capacity W,
|
||||
// then this item cannot be included
|
||||
// in the optimal solution
|
||||
if (wt[n - 1] > W) {
|
||||
return knapSack(W, wt, val, n - 1);
|
||||
if (wt[n - 1] > w) {
|
||||
return knapSack(w, wt, val, n - 1);
|
||||
} // Return the maximum of two cases:
|
||||
// (1) nth item included
|
||||
// (2) not included
|
||||
else {
|
||||
return Math.max(val[n - 1] + knapSack(W - wt[n - 1], wt, val, n - 1), knapSack(W, wt, val, n - 1));
|
||||
return Math.max(val[n - 1] + knapSack(w - wt[n - 1], wt, val, n - 1), knapSack(w, wt, val, n - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ public final class KadaneAlgorithm {
|
||||
private KadaneAlgorithm() {
|
||||
}
|
||||
|
||||
public static boolean maxSum(int[] a, int predicted_answer) {
|
||||
public static boolean maxSum(int[] a, int predictedAnswer) {
|
||||
int sum = a[0];
|
||||
int runningSum = 0;
|
||||
for (int k : a) {
|
||||
@ -22,7 +22,7 @@ public final class KadaneAlgorithm {
|
||||
// if running sum is negative then it is initialized to zero
|
||||
}
|
||||
// for-each loop is used to iterate over the array and find the maximum subarray sum
|
||||
return sum == predicted_answer;
|
||||
return sum == predictedAnswer;
|
||||
// It returns true if sum and predicted answer matches
|
||||
// The predicted answer is the answer itself. So it always return true
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public final class NewManShanksPrime {
|
||||
private NewManShanksPrime() {
|
||||
}
|
||||
|
||||
public static boolean nthManShanksPrime(int n, int expected_answer) {
|
||||
public static boolean nthManShanksPrime(int n, int expectedAnswer) {
|
||||
int[] a = new int[n + 1];
|
||||
// array of n+1 size is initialized
|
||||
a[0] = 1;
|
||||
@ -22,7 +22,7 @@ public final class NewManShanksPrime {
|
||||
a[i] = 2 * a[i - 1] + a[i - 2];
|
||||
}
|
||||
// The loop is continued till n
|
||||
return a[n] == expected_answer;
|
||||
return a[n] == expectedAnswer;
|
||||
// returns true if calculated answer matches with expected answer
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,16 @@ public final class SumOfSubset {
|
||||
private SumOfSubset() {
|
||||
}
|
||||
|
||||
public static boolean subsetSum(int[] arr, int num, int Key) {
|
||||
if (Key == 0) {
|
||||
public static boolean subsetSum(int[] arr, int num, int key) {
|
||||
if (key == 0) {
|
||||
return true;
|
||||
}
|
||||
if (num < 0 || Key < 0) {
|
||||
if (num < 0 || key < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean include = subsetSum(arr, num - 1, Key - arr[num]);
|
||||
boolean exclude = subsetSum(arr, num - 1, Key);
|
||||
boolean include = subsetSum(arr, num - 1, key - arr[num]);
|
||||
boolean exclude = subsetSum(arr, num - 1, key);
|
||||
|
||||
return include || exclude;
|
||||
}
|
||||
|
Reference in New Issue
Block a user