Advertisement
Guest User

Untitled

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