Problems trying program radixsort with vectors and tuples

-3

I want to order the second element of the tuple of vector v with radixSort and save the result in vector a.

vector<tuple<int, int, int>> a;

void countSort(vector<tuple<int, int, int>> &v, int n, int e) {
    int i;
    int o[10];
    for (i = 0; i < n; i++) {
        o[(get<1>(v[i]) / e) % 10]++;
    }

    for (i = 1; i < 10; i++) {
        o[i] += o[i - 1];
    }

    //The problem is in the next for cycle...
    for (i = n - 1; i >= 0; i--) {
        a[o[(get<1>(v[i]) / e) % 10] - 1] = v[i];
        o[(get<1>(v[i]) / e) % 10]--;
    }
}

void radixSort(vector<tuple<int, int, int>> &v) {
    for (int exp = 1; maxH/exp > 0; exp *= 10) {
        countSort(v, n, exp);
    }
}

  • When I run the program this shows this error:

    Process finished with exit code -1073741819 (0xC0000005)

c++
vector
tuples
radix-sort
asked on Stack Overflow Jun 26, 2018 by Alex Friedberg

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0