assoc. array sort or preserve order
Jesse Phillips
jessekphillips+D at gmail.com
Fri Sep 10 16:52:36 PDT 2010
Dr. Smith Wrote:
> Is there a way to preserve an array's original order, or to sort an assoc arr
> by key?
No, Associative arrays can not preserve this for performance reasons. Though you can do the following.
import std.algorithm;
import std.stdio;
void main() {
double [string][string] val;
auto keys = val.keys;
sort(keys);
foreach(key; keys) {
foreach(string2, col; val[key]) {
writefln("%s\t%s\t%f", val[key], string2, col);
}
}
}
More information about the Digitalmars-d-learn
mailing list