结构体构造函数以及排序
结构体初始化
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef struct Node {
int from;
int to;
Node() : from(0), to(0) {}
Node(int f, int t) : from(f), to(t) {}
}node;
int main()
{
node a;
node b(1, 2);
node c(6, 5);
node d(3, 5);
vector<Node>test;
test.push_back(a);
test.push_back(b);
test.push_back(c);
test.push_back(d);
cout << "before sort \n";
for (vector<Node>::iterator it = test.begin(); it != test.end(); it++)
cout << (*it).from << " " << (*it).to << endl;
sort(test.begin(), test.end(), [](Node a, Node b) {return a.from < b.from; });
cout << "after sort \n";
for (vector<Node>::iterator it = test.begin(); it != test.end(); it++)
cout << (*it).from << " " << (*it).to << endl;
return 0;
}