感谢C中的解决方案,现在我想使用std :: sort和vector在C++中实现这一点:
typedef struct
{
double x;
double y;
double alfa;
} pkt;
Run Code Online (Sandbox Code Playgroud)
vector< pkt > wektor;
使用push_back()填充; 比较功能:
int porownaj(const void *p_a, const void *p_b)
{
pkt *pkt_a = (pkt *) p_a;
pkt *pkt_b = (pkt *) p_b;
if (pkt_a->alfa > pkt_b->alfa) return 1;
if (pkt_a->alfa < pkt_b->alfa) return -1;
if (pkt_a->x > pkt_b->x) return 1;
if (pkt_a->x < pkt_b->x) return -1;
return 0;
}
sort(wektor.begin(), wektor.end(), porownaj); // this makes loads of errors …
Run Code Online (Sandbox Code Playgroud)