Guest User

Untitled

a guest
Dec 15th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <math.h>
  4. #include <cstdlib>
  5.  
  6. #define BASE 2
  7.  
  8. using namespace std;
  9.  
  10. vector<int> radix(vector<int> v) {
  11. vector<int> buc[BASE];
  12. for (int max = *max_element(v.begin(), v.end()), expo = 0; BASE * expo <= max; expo++) {
  13. int divisor = pow(BASE, expo);
  14. for (int n : v) buc[(n / divisor) % BASE].push_back(n);
  15. v.clear();
  16. for (int i = 0; i < BASE; i++) {
  17. v.insert(v.end(), buc[i].begin(), buc[i].end());
  18. buc[i].clear();
  19. }
  20. }
  21. return v;
  22. }
  23.  
  24. int main() {
  25. int arr[10];
  26. for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) arr[i] = rand() % 1000;
  27. vector<int> v(arr, arr + sizeof(arr) / sizeof(arr[0]));
  28.  
  29. v = radix(v);
  30.  
  31. for (int i : v) cout << i << " ";
  32. cout << endl;
  33. }
Add Comment
Please, Sign In to add comment