Skip to content

fix: removed warning for Sorts 'C-style array declaration of parameter 'array'' #1197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sorts/BogoSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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;
}
return true;
}

// 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++) {
Expand All @@ -29,7 +29,7 @@ private static <T> void nextPermutation(T array[]) {
}
}

public <T extends Comparable<T>> T[] sort(T array[]) {
public <T extends Comparable<T>> T[] sort(T[] array) {
while (!isSorted(array)) {
nextPermutation(array);
}
Expand Down
2 changes: 1 addition & 1 deletion Sorts/BubbleSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions Sorts/CombSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private int nextGap(int gap) {
* @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
Expand Down Expand Up @@ -62,9 +62,9 @@ public <T extends Comparable<T>> T[] sort(T arr[]) {
}

// 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");
Expand Down
14 changes: 7 additions & 7 deletions Sorts/RadixSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

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)
mx = arr[i];
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++)
Expand All @@ -33,7 +33,7 @@ private static void countSort(int arr[], int n, int exp) {
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);

Expand All @@ -43,14 +43,14 @@ private static void radixsort(int arr[], int n) {
}


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);
Expand Down