fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <unordered_set>
  5. #include <list>
  6.  
  7. template<typename T, typename U>
  8. void sorty(T& a, U const x){
  9. std::sort( a.begin(),a.end(), [&x](int i, int j)->bool { return x.at(i)>x.at(j);});
  10. }
  11.  
  12. int main() {
  13.  
  14. std::vector<int>toOrder(10);
  15. std::iota(toOrder.begin(),toOrder.end(),0);
  16. std::vector<double> orderBy {0.2,9.8,4.0,0.01,15.1,3.3,9.01,9.11,100.1,2.03};
  17.  
  18. sorty(toOrder,orderBy);
  19.  
  20. //std::unordered_set<double> orderBy_s(orderBy.begin(),orderBy.end()); //no .at()
  21. //std::list<int> toOrd_L(toOrder.begin(),toOrder.end()); //list
  22. //sorty(toOrd_L,orderBy_s);
  23.  
  24. for(auto i : toOrder){
  25. std::cout<<i <<"\t";
  26. }
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
8	4	1	7	6	2	5	9	0	3