#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Point { int x, y; }; struct Map { Point p; float f; }; bool cmp(Map x, Map y) { return x.f < y.f; } int main() { vector<Map> vec; for (int i = 0; i < 10; i ++) { Map mp; mp.p.x = i; mp.p.y = i+2; mp.f = (5-i) * 2.3; vec.push_back(mp); } for (int i = 0; i < vec.size(); i ++) { cout << vec[i].f << " "; } cout << "\n"; sort(vec.begin(), vec.end(), cmp); for (int i = 0; i < vec.size(); i ++) { cout << vec[i].f << " "; } cout << "\n"; return 0; }
时间: 2024-12-21 23:14:08