mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 03:59:38 +08:00
fix: removed warning for Sorts 'C-style array declaration of parameter 'array''
This commit is contained in:
@ -12,7 +12,7 @@ public class BogoSort implements SortAlgorithm {
|
||||
private static final Random random = new Random();
|
||||
|
||||
|
||||
private static <T extends Comparable<T>> boolean isSorted(T array[]) {
|
||||
private static <T extends Comparable<T>> boolean isSorted(T[] array) {
|
||||
for (int i = 0; i < array.length - 1; i++) {
|
||||
if (SortUtils.less(array[i + 1], array[i])) return false;
|
||||
}
|
||||
@ -20,7 +20,7 @@ public class BogoSort implements SortAlgorithm {
|
||||
}
|
||||
|
||||
// Randomly shuffles the array
|
||||
private static <T> void nextPermutation(T array[]) {
|
||||
private static <T> void nextPermutation(T[] array) {
|
||||
int length = array.length;
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
@ -29,7 +29,7 @@ public class BogoSort implements SortAlgorithm {
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Comparable<T>> T[] sort(T array[]) {
|
||||
public <T extends Comparable<T>> T[] sort(T[] array) {
|
||||
while (!isSorted(array)) {
|
||||
nextPermutation(array);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class BubbleSort implements SortAlgorithm {
|
||||
**/
|
||||
|
||||
@Override
|
||||
public <T extends Comparable<T>> T[] sort(T array[]) {
|
||||
public <T extends Comparable<T>> T[] sort(T[] array) {
|
||||
for (int i = 0, size = array.length; i < size - 1; ++i) {
|
||||
boolean swapped = false;
|
||||
for (int j = 0; j < size - 1 - i; ++j) {
|
||||
|
@ -33,7 +33,7 @@ class CombSort implements SortAlgorithm {
|
||||
* @return sorted array
|
||||
*/
|
||||
@Override
|
||||
public <T extends Comparable<T>> T[] sort(T arr[]) {
|
||||
public <T extends Comparable<T>> T[] sort(T[] arr) {
|
||||
int size = arr.length;
|
||||
|
||||
// initialize gap
|
||||
@ -62,9 +62,9 @@ class CombSort implements SortAlgorithm {
|
||||
}
|
||||
|
||||
// Driver method
|
||||
public static void main(String args[]) {
|
||||
public static void main(String[] args) {
|
||||
CombSort ob = new CombSort();
|
||||
Integer arr[] = {8, 4, 1, 56, 3, -44, -1, 0, 36, 34, 8, 12, -66, -78, 23, -6, 28, 0};
|
||||
Integer[] arr = {8, 4, 1, 56, 3, -44, -1, 0, 36, 34, 8, 12, -66, -78, 23, -6, 28, 0};
|
||||
ob.sort(arr);
|
||||
|
||||
System.out.println("sorted array");
|
||||
|
@ -4,7 +4,7 @@ import java.util.Arrays;
|
||||
|
||||
class RadixSort {
|
||||
|
||||
private static int getMax(int arr[], int n) {
|
||||
private static int getMax(int[] arr, int n) {
|
||||
int mx = arr[0];
|
||||
for (int i = 1; i < n; i++)
|
||||
if (arr[i] > mx)
|
||||
@ -12,10 +12,10 @@ class RadixSort {
|
||||
return mx;
|
||||
}
|
||||
|
||||
private static void countSort(int arr[], int n, int exp) {
|
||||
int output[] = new int[n];
|
||||
private static void countSort(int[] arr, int n, int exp) {
|
||||
int[] output = new int[n];
|
||||
int i;
|
||||
int count[] = new int[10];
|
||||
int[] count = new int[10];
|
||||
Arrays.fill(count, 0);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
@ -33,7 +33,7 @@ class RadixSort {
|
||||
arr[i] = output[i];
|
||||
}
|
||||
|
||||
private static void radixsort(int arr[], int n) {
|
||||
private static void radixsort(int[] arr, int n) {
|
||||
|
||||
int m = getMax(arr, n);
|
||||
|
||||
@ -43,14 +43,14 @@ class RadixSort {
|
||||
}
|
||||
|
||||
|
||||
static void print(int arr[], int n) {
|
||||
static void print(int[] arr, int n) {
|
||||
for (int i = 0; i < n; i++)
|
||||
System.out.print(arr[i] + " ");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
int arr[] = {170, 45, 75, 90, 802, 24, 2, 66};
|
||||
int[] arr = {170, 45, 75, 90, 802, 24, 2, 66};
|
||||
int n = arr.length;
|
||||
radixsort(arr, n);
|
||||
print(arr, n);
|
||||
|
Reference in New Issue
Block a user