Refactor Code Style (#4151)

This commit is contained in:
Saurabh Rahate
2023-04-15 13:55:54 +05:30
committed by GitHub
parent 1ce907625b
commit 1dc388653a
100 changed files with 293 additions and 319 deletions

View File

@ -42,10 +42,10 @@ class BinarySearch implements SearchAlgorithm {
* @return the location of the key
*/
private <T extends Comparable<T>> int search(
T array[],
T key,
int left,
int right
T[] array,
T key,
int left,
int right
) {
if (right < left) {
return -1; // this means that the key not found

View File

@ -21,7 +21,7 @@ class InterpolationSearch {
* @param key is a value what shoulb be found in the array
* @return an index if the array contains the key unless -1
*/
public int find(int array[], int key) {
public int find(int[] array, int key) {
// Find indexes of two corners
int start = 0, end = (array.length - 1);

View File

@ -8,7 +8,7 @@ class KMPSearch {
// create lps[] that will hold the longest
// prefix suffix values for pattern
int lps[] = new int[M];
int[] lps = new int[M];
int j = 0; // index for pat[]
// Preprocess the pattern (calculate lps[]
@ -38,7 +38,7 @@ class KMPSearch {
return -1;
}
void computeLPSArray(String pat, int M, int lps[]) {
void computeLPSArray(String pat, int M, int[] lps) {
// length of the previous longest prefix suffix
int len = 0;
int i = 1;

View File

@ -13,7 +13,7 @@ package com.thealgorithms.searches;
public class OrderAgnosticBinarySearch {
static int BinSearchAlgo(int arr[], int start, int end, int target) {
static int BinSearchAlgo(int[] arr, int start, int end, int target) {
// Checking whether the given array is ascending order
boolean AscOrd = arr[start] < arr[end];

View File

@ -28,9 +28,9 @@ public class SaddlebackSearch {
* @return The index(row and column) of the element if found. Else returns
* -1 -1.
*/
private static int[] find(int arr[][], int row, int col, int key) {
private static int[] find(int[][] arr, int row, int col, int key) {
// array to store the answer row and column
int ans[] = { -1, -1 };
int[] ans = { -1, -1 };
if (row < 0 || col >= arr[row].length) {
return ans;
}
@ -54,7 +54,7 @@ public class SaddlebackSearch {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int arr[][];
int[][] arr;
int i, j, rows = sc.nextInt(), col = sc.nextInt();
arr = new int[rows][col];
for (i = 0; i < rows; i++) {
@ -64,7 +64,7 @@ public class SaddlebackSearch {
}
int ele = sc.nextInt();
// we start from bottom left corner
int ans[] = find(arr, rows - 1, 0, ele);
int[] ans = find(arr, rows - 1, 0, ele);
System.out.println(ans[0] + " " + ans[1]);
sc.close();
}

View File

@ -21,7 +21,7 @@ public class SquareRootBinarySearch {
*
* @param args Command line arguments
*/
public static void main(String args[]) {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(
"Enter a number you want to calculate square root of : "

View File

@ -1,7 +1,7 @@
package com.thealgorithms.searches;
import java.util.*;
public class sortOrderAgnosticBinarySearch {
public static int find(int arr[],int key){
public static int find(int[] arr, int key){
int start = 0;
int end = arr.length-1;
boolean arrDescending = arr[start]>arr[end]; //checking for Array is in ascending order or descending order.