Skip to content

Instantly share code, notes, and snippets.

@fredrb
Created November 17, 2014 10:46
Show Gist options
  • Save fredrb/419300082452c99ddc5e to your computer and use it in GitHub Desktop.
Save fredrb/419300082452c99ddc5e to your computer and use it in GitHub Desktop.
Bucket sort
void bSort(int arr[], int size, int max){
int bucket[max];
int resultIndex = 0;
for(int i = 0; i < max; i++)
bucket[i] = 0;
for(int i = 0; i < size; i++)
bucket[arr[i]]++;
for(int i = 0; i < max; i++){
if(bucket[i] != 0)
for(int j = 0; j < bucket[i] ; j++)
arr[resultIndex++] = i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment