You can use qsort() function.
#include <iostream>
#include <cstdlib>
const int LOCAL_SIZE = 10;
struct radius {
double r; double angle; double x; double y;
};
int ascending(const void *d1, const void *d2);
int main(void) {
radius LOCAL[LOCAL_SIZE] = {
{ -1, },
{ 0, },
{ 7, },
{ 2, },
{ 6, },
{ 5, },
{ 8, },
{ 9.9, },
{ 138, },
{ -1666 }
};
qsort(LOCAL, LOCAL_SIZE, sizeof(radius), ascending);
for (radius &d : LOCAL) {
std::cout << d.r << std::endl;
}
return 0;
}
int ascending(const void *pd1, const void *pd2) {
const radius *r1 = (const radius *)pd1, *r2 = (const radius *)pd2;
if (r1->r > r2->r)
{
return 1;
}
else if (r1->r < r2->r)
{
return -1;
}
else
{
return 0;
}
}
std::sortwith your non-vectorofstructs?