Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "iostream"
- #include "ctime"
- #include "cstdlib"
- using namespace std;
- const int bitsword = 32;
- const int bitsbyte = 8 ;
- const int bytesword = bitsword/bitsbyte;
- const int R=1 << bitsbyte;
- inline int digit (long A, int B)
- { return (A >> bitsbyte*(bytesword-B-1) & (R-1)); }
- template <class Item>
- void radixLSD (Item a[] , int l, int r,int maxN)
- { Item *aux=new Item[maxN];
- for (int d = bytesword-1; d >= 0; d--)
- {
- int i, j, count[R+1];
- for (j = 0; j < R; j++) count[j] = 0;
- for (i = 1; i <= r; i++)
- count[digit(a[i] , d) + 1]++;
- for (j = 1; j < R; j++)
- count[j] += count[j-l];
- for (i = 1; i <= r; i++)
- aux[count[digit(a[i] , d)]++] = a[i];
- for (i = 1; i <= r; i++) a[i] = aux[i];
- }
- }
- int main () {
- int a[10];
- srand(time(NULL));
- for (int i=0; i<10; i++) {
- a[i]=rand () %100;
- cout << a[i] << " ";
- }
- cout << endl;
- radixLSD (a, 0, 5, 10);
- for (int i=0; i<10; i++)
- cout << a[i] << " ";
- cout << endl;
- system ("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment