Sorting a TArray of structs
Its content is for example this (first column are indexes):
How would I sort it on a, so to have this output?
Thanks in advance!
asked Mar 07 '16 at 09:20 PM in C++ Programming
You can sort by using TArray's Sort member function and a lambda (C++11 feature) which describes how your elements are to be sorted. If you want to sort by a, then b, then c, then you should have something like:
Hope this helps,
answered Mar 08 '16 at 04:19 PM
Steve Robb STAFF
TArray has a function for sorting
In order to work with your struct or class you need to override > operator that should declere if inputed A is bigger the B, then soft function to the rest with help of that operator
answered Mar 07 '16 at 11:53 PM
There might be an easier way, but the way I've done it in the past is create a class that overloads operator(). It would look something like
Implement your comparison however you want in that function and just pass in instance of the Sorter class to TArray::Sort.
Follow this question
Once you sign in you will be able to subscribe for any updates here