Created
January 24, 2018 12:06
-
-
Save keehyun2/35e831412a4de01dc2a218e07d174a57 to your computer and use it in GitHub Desktop.
bucketSort
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
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