fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. // Function used to compare two ints
  6. bool compareInt(int a, int b)
  7. {
  8. return a < b;
  9. }
  10.  
  11. int main(){
  12.  
  13. std::vector<int> time={5, 16, 4, 7};
  14. std::vector<int> amplitude={10,17,8,16};
  15. std::vector<int> index(time.size(), 0);
  16.  
  17. for (int i = 0 ; i != index.size() ; i++) {
  18. index[i] = i;
  19. }
  20.  
  21. // This sort method uses a function (compareInt) to compare the elements
  22. sort(index.begin(), index.end(), compareInt);
  23.  
  24. std::cout << "Time \t Ampl \t idx" << std::endl;
  25. for (int ii = 0 ; ii != index.size() ; ++ii) {
  26. std::cout << time[index[ii]] << " \t " << amplitude[index[ii]] << " \t " << index[ii] << std::endl;
  27. }
  28. }
Success #stdin #stdout 0s 4316KB
stdin
Standard input is empty
stdout
Time 	 Ampl 	 idx
5 	 10 	 0
16 	 17 	 1
4 	 8 	 2
7 	 16 	 3