(int arr[])
| 4 | |
| 5 | public class CountingSort { |
| 6 | public static void countingSort(int arr[]) { |
| 7 | int largest = Integer.MIN_VALUE; |
| 8 | for(int i=0; i<arr.length; i++) { |
| 9 | largest = Math.max(largest, arr[i]); |
| 10 | } |
| 11 | |
| 12 | int count[] = new int[largest+1]; |
| 13 | for(int i=0; i<arr.length; i++) { |
| 14 | count[arr[i]]++; |
| 15 | } |
| 16 | int j = 0; |
| 17 | for(int i=0; i<count.length; i++) { |
| 18 | while(count[i] > 0) { |
| 19 | arr[j] = i; |
| 20 | j++; |
| 21 | count[i]--; |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | public static void countingSortDescending(int arr[]) { |
| 27 | int largest = Integer.MIN_VALUE; |
nothing calls this directly
no outgoing calls
no test coverage detected