发布网友
共1个回答
热心网友
试试我的代码:
# include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Re
{
struct F
{
double x;
double y;
};
};
int cmp(const struct Re::F &aa, const struct Re::F &bb) //::引用结构中的结构
{
if(aa.x < bb.x)
return 1;
return 0;
}
int main (void)
{
vector<Re::F> v;
struct Re::F f1, f2;
f1.x = 2.1;
f1.y = 2.1;
v.push_back(f1);
f2.x = 1.1;
f2.y = 1.1;
v.push_back(f2);
sort(v.begin(), v.end(), cmp);
for(vector<Re::F>::iterator it = v.begin(); it != v.end();it++)
{
cout << (*it).x << "\t" << (*it).y << endl;
}
return 0;}