Sorting indices (provided that it is a number from 0 to N sequentially), for example:
std::sort(indices.begin(), indices.end(), compareFunc);
using the comparison function, for example:
bool compareFunc(int &a, int &b)
{
return predictions[a] > predictions[b];
}
This only sorts indexes, but forecasts can be accessed in sorted order using index values from indexes!
Code:
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
vector<double> predictions{ 1.22, 3.22, 2.22, 4.22 };
vector<int> indices{ 0, 1, 2, 3 };
bool compareFunc(int &a, int &b) {
return predictions[a] > predictions[b];
}
int main()
{
std::sort(indices.begin(), indices.end(), compareFunc);
for (auto i: indices) {
cout << i << "\t" << predictions[i] << endl;
}
return 0;
}
source
share