Answer the question
In order to leave comments, you need to log in
How to sort a vector by one of the structure elements?
There is a structure that stores some parameters:
typedef struct
{
sf::Vector2f position; // Координаты
float angle; // Угол относительно оси
float thrust; // Тяга трастера
//... и так далее
} calcThrusterType;
std::vector <calcThrusterType> thrusters;
Answer the question
In order to leave comments, you need to log in
std::sort(thrusters.begin(), thrusters.end(),
[](const calcThrusterType& x, const calcThrusterType& y) {
return (x.angle < y.angle);
});
bool angleLess(const cTT& x, const cTT& y) { return x.angle < y.angle; }
std::sort(thrusters.begin(), thrusters.end(), angleLess);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question