Skip to content

Instantly share code, notes, and snippets.

@keehyun2
Created January 24, 2018 12:06
Show Gist options
  • Save keehyun2/35e831412a4de01dc2a218e07d174a57 to your computer and use it in GitHub Desktop.
Save keehyun2/35e831412a4de01dc2a218e07d174a57 to your computer and use it in GitHub Desktop.
bucketSort
void bucketSort(int[] a, int maxVal) {
int [] bucket=new int[maxVal+1];
for (int i=0; i<bucket.length; i++) {
bucket[i]=0;
}
for (int i=0; i<a.length; i++) {
bucket[a[i]]++;
}
int outPos=0;
for (int i=0; i<bucket.length; i++) {
for (int j=0; j<bucket[i]; j++) {
a[outPos++]=i;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment