Skip to content

Instantly share code, notes, and snippets.

@kuzemkon
Created June 13, 2016 14:21
Show Gist options
  • Save kuzemkon/1d3e89f3eefe09e1bdee0dd8358b153b to your computer and use it in GitHub Desktop.
Save kuzemkon/1d3e89f3eefe09e1bdee0dd8358b153b to your computer and use it in GitHub Desktop.
Counting Sorting
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