0

Following C++ sorting and keeping track of indexes : This is how to get the argsort of vector<int> v

vector<int> VectorArgSort(vector<int> &v) {
    /* Get the indices that gives a sorted vector v*/

    vector<int> retIndices(v.size());
    iota(retIndices.begin(), retIndices.end(), 0);

    stable_sort(
        retIndices.begin(), retIndices.end(),
        [&v](int i1, int i2) {return v[i1] < v[i2];});

    return retIndices;
}

But what i want is to have vector<int> VectorArgSort(vector<float> &v) that still gives vector because they are indices, but to perform it on vector<float> &v instead.

I tried changing several of the defined int types to doubles, but i dont think i should because they all points towards the indices. So im not sure how to change the function to get what i want.

leonardltk1
  • 257
  • 1
  • 4
  • 18

1 Answers1

0

You only have to change the vector<int> to vector<float> in the argument of the function.

vector<int> VectorArgSort(vector<float> &v) {

see working version here

Thomas
  • 4,980
  • 2
  • 15
  • 30