Skip to content
Merged
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
13 changes: 13 additions & 0 deletions Sorting-algorithms/Radixsort.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public static void main(String[] args) {
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
if (containsNegative(arr)) {
System.out.println("This radix sort version supports non-negative integers only");
sc.close();
return;
}
System.out.println("Entered array : " + Arrays.toString(arr));
radixsort(arr);
System.out.println("Sorted array : " + Arrays.toString(arr));
Expand All @@ -50,6 +55,14 @@ public static int getMax(int[] arr) {
}
return max;
}
public static boolean containsNegative(int[] arr) {
for (int value : arr) {
if (value < 0) {
return true;
}
}
return false;
}
public static void countSort(int[] arr, int exp) {
int n = arr.length;
int[] output = new int[n];
Expand Down
Loading