Guest User

Untitled

a guest
Aug 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. double IAlgorithm::radixSort(){
  2. int *tmp = this->duplicate();
  3. clock_t start = clock();
  4.  
  5. int i,b[SIZE],m=0,exp=1;
  6. for(i=0;i<SIZE;i++)
  7. {
  8. if(tmp[i]>m)
  9. m=tmp[i];
  10. }
  11.  
  12. while(m/exp>0)
  13. {
  14. int bucket[10]={0};
  15. for(i=0;i<SIZE;i++)
  16. bucket[tmp[i]/exp%10]++;
  17. for(i=1;i<10;i++)
  18. bucket[i]+=bucket[i-1];
  19. for(i=SIZE-1;i>=0;i--)
  20. b[--bucket[tmp[i]/exp%10]]=tmp[i];
  21. for(i=0;i<SIZE;i++)
  22. tmp[i]=b[i];
  23. exp*=10;
  24.  
  25. }
  26.  
  27. clock_t end = clock();
  28. delete [] tmp;
  29. return double(end-start) / CLOCKS_PER_SEC;
  30. }
Add Comment
Please, Sign In to add comment