Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double IAlgorithm::radixSort(){
- int *tmp = this->duplicate();
- clock_t start = clock();
- int i,b[SIZE],m=0,exp=1;
- for(i=0;i<SIZE;i++)
- {
- if(tmp[i]>m)
- m=tmp[i];
- }
- while(m/exp>0)
- {
- int bucket[10]={0};
- for(i=0;i<SIZE;i++)
- bucket[tmp[i]/exp%10]++;
- for(i=1;i<10;i++)
- bucket[i]+=bucket[i-1];
- for(i=SIZE-1;i>=0;i--)
- b[--bucket[tmp[i]/exp%10]]=tmp[i];
- for(i=0;i<SIZE;i++)
- tmp[i]=b[i];
- exp*=10;
- }
- clock_t end = clock();
- delete [] tmp;
- return double(end-start) / CLOCKS_PER_SEC;
- }
Add Comment
Please, Sign In to add comment