Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BucketSort
//clang 3.8.0 #include <iostream> int getMax(int *A,int len){ int max=A[0]; for(int i=1;i<len;++i ){ if(A[i]>max)max=A[i]; } return max; } void BucketSort(int *A,int len ){ const int max=getMax(A,len); int bucket[max]; for(int i=0;i<max;++i ){ bucket[i]=0; } for(int i=0;i<len;++i ){ ++bucket[A[i]]; } for(int i=0,j=0;i<=max;++i ){ while(bucket[i]>0){ A[j++]=i; --bucket[i]; } } } int main() { int A[]{9,5,4,2,3,7,9,2,1,3,0}; int len=sizeof(A)/sizeof(A[0]); BucketSort(A,len); for(int i:A ) std::cout <<i<<' '; }
run
|
edit
|
history
|
help
0
IsContainer
Crow unordered_map Quiz
nontype template parameter produced with decltype for function
ArrayList Example Starter Code 2
Atomic trivial default constructor
11/29
Composite pattern
Te
Wrapper to pass shared_ptr to &, const &, *, const * through std::bind.
Example Node Program