MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / countingSort

Method countingSort

Programs/CountingSort.java:16–39  ·  view source on GitHub ↗
(int arr[])

Source from the content-addressed store, hash-verified

14 }
15
16 static int[] countingSort(int arr[])
17 {
18 int n = arr.length;
19
20 int result[] = new int[n];
21
22 int count[] = new int[9];
23 for (int i=0; i<9; ++i)
24 count[i] = 0;
25
26 for (int i=0; i<n; ++i)
27 ++count[arr[i]];
28
29 for (int i=1; i<=8; ++i)
30 count[i] += count[i-1];
31
32 for (int i = 0; i<n; ++i)
33 {
34 result[count[arr[i]]-1] = arr[i];
35 --count[arr[i]];
36 }
37
38 return result;
39 }
40
41}

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected