fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int compare(const void *a, const void *b) {
  7. int x = ((pair<int,int>*)a)->first;
  8. int y = ((pair<int,int>*)b)->first;
  9. return x - y;
  10. }
  11.  
  12.  
  13. int main() {
  14.  
  15. int m = 3;
  16.  
  17. vector<pair<int, int>> weight(m);
  18.  
  19. weight[0].first = 3;
  20. weight[0].second = 0;
  21.  
  22. weight[1].first = 2;
  23. weight[1].second = 5;
  24.  
  25. weight[2].first = 1;
  26. weight[2].second = 6;
  27.  
  28. for (int i = 0; i < m; i++) {
  29. cout << weight[i].first << " " << weight[i].second << endl;
  30. }
  31.  
  32. cout << endl;
  33.  
  34. qsort(&weight[0].first, m, sizeof(weight[0]), compare);
  35.  
  36. for (int i = 0; i < m; i++) {
  37. cout << weight[i].first << " " << weight[i].second << endl;
  38. }
  39.  
  40.  
  41.  
  42. return 0;
  43. }
  44.  
  45.  
Success #stdin #stdout 0s 5548KB
stdin
Standard input is empty
stdout
3 0
2 5
1 6

1 6
2 5
3 0