Created
November 17, 2014 10:46
-
-
Save fredrb/419300082452c99ddc5e to your computer and use it in GitHub Desktop.
Bucket sort
This file contains 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 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