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]);
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/266066.html