How to sort a 2D array by column
Chris Cain via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 7 12:18:32 PDT 2014
On Saturday, 7 June 2014 at 19:14:01 UTC, Chris Cain wrote:
>> This is my attemot to create a compare object. But I don't
>> know how to use it together with .sort member function
>
>
> Don't use the .sort property. Use std.algorithm.sort, which has
> a "less" predicate (that should return a bool).
>
> http://dlang.org/phobos/std_algorithm.html#sort
Also note that the examples use a string to define the predicate,
but it accepts functions as well. Such as:
bool myCompareFunc(AType lhs, AType rhs)
{
return lhs.blah < rhs.blah;
}
//...
AType[] arr;
//...
arr.sort!myCompareFunc();
More information about the Digitalmars-d-learn
mailing list