0

I see this other post about sort qvector: post_sort_qvector_simple

But I need some method to sort elements of my QVector.

I have something like this:

CartesianPoint point
std::vector<CartesianPoint> vector_points;

Where CartesianPoint is:

class CartesianPoint
{

public:

    double x;
    double y;
    double z;

}

Then I need to sort vector_points only for z element of Cartesian point.

I know this is not possible but I need something like this

std::vector(vector_points.z.begin(), vector_points.z.end());

How I would solve this?

Community
  • 1
  • 1
Iván
  • 67
  • 11
  • Sorry but I didn't see this post. Could you type link here?? – Iván Mar 16 '17 at 14:49
  • http://stackoverflow.com/questions/1380463/sorting-a-vector-of-custom-objects – NathanOliver Mar 16 '17 at 14:51
  • `std::sort(std::begin(vector_points), std::end(vector_points), [](auto const& a, auto const& b) { return (a.z < b.z); });` this sorts from least to greatest `z` value. See it [run here](http://ideone.com/ABKXTG). – ssell Mar 16 '17 at 14:54
  • Thanks it works fine. What I would do with this post? – Iván Mar 16 '17 at 15:12
  • Hi, I have a this problem. I have a vector like this: [vector_points_original](https://github.com/ivanoterouvigo/gbxml/blob/master/imgs/vector_points_001.png) – Iván Mar 17 '17 at 16:51

0 Answers0