-3

I have a struct MyType that contain

int a; 
int b;

and I have a vector of that type my_vec

I need to do a custom sort to sort the vector according to a

what's the best way to do that?

SleuthEye
  • 14,379
  • 2
  • 32
  • 61

1 Answers1

2

Try this:

std::sort(my_vec.begin(), my_vec.end(), [](const MyType& t1, const MyType& t2) { return t1->a< t2->a; });
Hazem Abdullah
  • 1,837
  • 4
  • 23
  • 41