Created
June 13, 2016 14:21
-
-
Save kuzemkon/1d3e89f3eefe09e1bdee0dd8358b153b to your computer and use it in GitHub Desktop.
Counting Sorting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Sort { | |
private int[] A; | |
private int[] B; | |
private int[] C; | |
private int k; | |
public Sort(int[] array, int k){ | |
this.B = this.countingSort(array,k); | |
} | |
private int[] countingSort(int[] a, int k) { | |
int c[] = new int[k]; | |
for (int i = 0; i < a.length; i++) | |
c[a[i]]++; | |
for (int i = 1; i < k; i++) | |
c[i] += c[i-1]; | |
int b[] = new int[a.length]; | |
for (int i = a.length-1; i >= 0; i--) | |
b[--c[a[i]]] = a[i]; | |
return b; | |
} | |
public int[] getResult(){ | |
return this.B; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment