summaryrefslogtreecommitdiff
path: root/c,cc/sort.cc
blob: 165b0862aaf6d944fa90db1e0a6e19eb9f678889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;


struct X
{
  pair<string,int> p;
};

bool myf(X a, X b)
{
  return a.p.second > b.p.second;
}

int main(void)
{
  X a;
  a.p.first = "a";
  a.p.second = 1;

  X b;
  b.p.first = "b";
  b.p.second = 2;

  X c;
  c.p.first = "c";
  c.p.second = 3;

  vector<X> v;
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);

  for (unsigned i = 0; i < v.size(); i++) {
    cout << v[i].p.first << endl;
  }
  sort(v.begin(), v.end(), myf);
  cout << endl;
  for (unsigned i = 0; i < v.size(); i++) {
    cout << v[i].p.first << endl;
  }
}