import std.random; import std.stdio; import std.string; struct Box { int volume; int opCmp(const ref Box box) const { return (volume == box.volume ? box.volume - volume: volume - box.volume); } string toString() const { return format("Volume:%s\n", volume); } } void main() { Box[] boxes; int j = 10; foreach (i; 0 .. 10) { boxes ~= Box(j*j*j); j = j-1; } writeln("Unsorted Array"); writeln(boxes); boxes.sort; writeln("Sorted Array"); writeln(boxes); writeln(boxes[0]<boxes[1]); writeln(boxes[0]>boxes[1]); writeln(boxes[0]<=boxes[1]); writeln(boxes[0]>=boxes[1]); }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more