Guest User

Untitled

a guest
May 30th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include "iostream"
  2. #include "ctime"
  3. #include "cstdlib"
  4.  
  5. using namespace std;
  6.  
  7. const int bitsword = 32;
  8. const int bitsbyte = 8 ;
  9. const int bytesword = bitsword/bitsbyte;
  10. const int R=1 << bitsbyte;
  11.  
  12. inline int digit (long A, int B)
  13. { return (A >> bitsbyte*(bytesword-B-1) & (R-1)); }
  14.  
  15. template <class Item>
  16. void radixLSD (Item a[] , int l, int r,int maxN)
  17. { Item *aux=new Item[maxN];
  18. for (int d = bytesword-1; d >= 0; d--)
  19. {
  20. int i, j, count[R+1];
  21. for (j = 0; j < R; j++) count[j] = 0;
  22. for (i = 1; i <= r; i++)
  23. count[digit(a[i] , d) + 1]++;
  24. for (j = 1; j < R; j++)
  25. count[j] += count[j-l];
  26. for (i = 1; i <= r; i++)
  27. aux[count[digit(a[i] , d)]++] = a[i];
  28. for (i = 1; i <= r; i++) a[i] = aux[i];
  29. }
  30. }
  31.  
  32. int main () {
  33. int a[10];
  34. srand(time(NULL));
  35. for (int i=0; i<10; i++) {
  36. a[i]=rand () %100;
  37. cout << a[i] << " ";
  38. }
  39. cout << endl;
  40. radixLSD (a, 0, 5, 10);
  41. for (int i=0; i<10; i++)
  42. cout << a[i] << " ";
  43. cout << endl;
  44. system ("pause");
  45. }
Advertisement
Add Comment
Please, Sign In to add comment