Re: How to sort a 2D array by column

2014-06-07 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 7 June 2014 at 20:47:31 UTC, katuday wrote: On Saturday, 7 June 2014 at 19:18:34 UTC, Chris Cain wrote: 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 D

Re: How to sort a 2D array by column

2014-06-07 Thread katuday via Digitalmars-d-learn
On Saturday, 7 June 2014 at 19:18:34 UTC, Chris Cain wrote: 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

Re: How to sort a 2D array by column

2014-06-07 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 7 June 2014 at 19:06:10 UTC, katuday wrote: the_table.sort; // I believe this sort uses all the columns inside the_row. What I want is use specific column(s) Supposing you use the *function* "std.algorithm.sort", then that is going to sort you rows according to the (default) pred

Re: How to sort a 2D array by column

2014-06-07 Thread Ali Çehreli via Digitalmars-d-learn
On 06/07/2014 12:18 PM, Chris Cain wrote: 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; //... a

Re: How to sort a 2D array by column

2014-06-07 Thread Chris Cain via Digitalmars-d-learn
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:

Re: How to sort a 2D array by column

2014-06-07 Thread Chris Cain via Digitalmars-d-learn
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

How to sort a 2D array by column

2014-06-07 Thread katuday via Digitalmars-d-learn
I have a dynamic array of dynamic array of strings I want to sort the outer array based on specific columns of the inner array This is how I am populating the 2D array void readFromFile() { alias Row = string[]; alias Table = Row[]; Row the_row; Table t