MCPcopy Create free account
hub / github.com/apna-college/Alpha / countingSort

Method countingSort

2_Basic Sorting/CountingSort.java:6–24  ·  view source on GitHub ↗
(int arr[])

Source from the content-addressed store, hash-verified

4
5public 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;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected