fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <numeric>
  4. #include <algorithm>
  5.  
  6. class Compare
  7. {
  8. public:
  9. Compare (const std::vector<double> &v) : m_v (v) {}
  10. bool operator () (int i, int j) const { return m_v [i] < m_v [j]; }
  11.  
  12. private:
  13. const std::vector<double> &m_v;
  14. };
  15.  
  16. std::vector<int> order_ideal(const std::vector<double>& x) {
  17. std::vector<int> idx(x.size());
  18. std::iota(idx.begin(), idx.end(), 0);
  19. Compare c (x);
  20. std::sort(idx.begin(), idx.end(), c);
  21. return idx;
  22. }
  23.  
  24. int main ()
  25. {
  26. std::vector <double> x (20);
  27. order_ideal (x);
  28. }
Success #stdin #stdout 0s 4552KB
stdin
Standard input is empty
stdout
Standard output is empty