Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. long long radixSort(int*& arr, int n)
  2. {
  3. int digit = 0;
  4.  
  5. RadixUnion* temp = new RadixUnion[n];
  6.  
  7.  
  8.  
  9. while (digit < 4) {
  10.  
  11. for (int i = 0; i < n; i++) {
  12.  
  13. temp[i].num = (unsigned int)arr[i];
  14.  
  15. }
  16.  
  17. int* c = new int[256];
  18.  
  19. for (int i = 0; i < 256; i++) {
  20.  
  21. c[i] = 0;
  22.  
  23. }
  24.  
  25.  
  26. for (int i = 0; i < n; i++) {
  27.  
  28. c[temp[i].set[digit]]++;
  29.  
  30. }
  31.  
  32.  
  33. long long k = 0, j;
  34.  
  35.  
  36.  
  37. for (int i = 0; i < 256; i++) {
  38.  
  39. j = c[i];
  40. c[i] = k;
  41. k += j;
  42.  
  43. }
  44.  
  45.  
  46. for (int i = 0; i < n; i++) {
  47.  
  48. int tempIndex = temp[i].set[digit];
  49.  
  50. arr[c[tempIndex]] = temp[i].num;
  51.  
  52. c[tempIndex]++;
  53.  
  54. }
  55.  
  56. digit++;
  57.  
  58. delete[] c;
  59. }
  60.  
  61. delete[] temp;
  62. return count;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement