Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long long radixSort(int*& arr, int n)
- {
- int digit = 0;
- long long count = 1; // digit = 0
- RadixUnion* temp = new RadixUnion[n];
- count += 1; // RadixUnion *temp = new RadixUnion[n]
- count += 1; // digit < 4
- while (digit < 4) {
- count += 2; // i = 0; i < n
- for (int i = 0; i < n; i++) {
- count += 3; // i < n; i++
- temp[i].num = (unsigned int)arr[i];
- count += 4; // temp[i].num = (unsigned int)arr[i]
- }
- int* c = new int[256];
- count += 1; // *c = new int[256]
- count += 2; // i = 0; i < 256
- for (int i = 0; i < 256; i++) {
- count += 3; // i < 256; i++
- c[i] = 0;
- count += 2; // c[i] = 0
- }
- count += 2; // i = 0; i < n
- for (int i = 0; i < n; i++) {
- count += 3; // i < n; i++
- c[temp[i].set[digit]]++;
- count += 6; // c[temp[i].set[digit]]++
- }
- long long k = 0, j;
- count += 1; // k = 0
- count += 2; // i = 0; i < 256
- for (int i = 0; i < 256; i++) {
- count += 3; // i < 256; i++
- j = c[i];
- c[i] = k;
- k += j;
- count += 6; // j = c[i]; c[i] = k; k += j
- }
- count += 2; // i = 0; i < n
- for (int i = 0; i < n; i++) {
- count += 3; // i < n; i++
- int tempIndex = temp[i].set[digit];
- count += 4; // tempIndex = temp[i].set[digit]
- arr[c[tempIndex]] = temp[i].num;
- count += 5; // arr[c[tempIndex]] = temp[i].num
- c[tempIndex]++;
- count += 3; // c[tempIndex]++
- }
- digit++;
- count += 2; // digit++
- delete[] c;
- }
- delete[] temp;
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement